0

im new in macro programming and vb
im doing a project office automation
how do i open (without showing) existing excel?
so i can manipulate the data

most of the snipet i see in the net is like this

Set oExcel = CreateObject("Excel.Application")
Set ExcelDoc = oExcel.Workbooks.Open(m_strPath & "project.xls")

i want the user to choose which excel file to edit
so a dialog box should prompt out
im thinking of using a dialog box
but i couldnt find any dialogbox button in vb 6


please help me
thanks in advance

2
Contributors
1
Reply
9
Views
10 Years
Discussion Span
Last Post by kb.net
0

Hi,

Check below example, for it to work add the component "Microsoft Common Dialouge Control" and add one to your form:

Private Sub Command1_Click()

Dim xl
Dim xlsheet
Dim xlwbook
Dim FilNam As String

    Me.CommonDialog1.ShowOpen
    FilNam = Me.CommonDialog1.FileName

    If Me.CommonDialog1.FileName <> "" Or Me.CommonDialog1.FileName <> ".xls" Then
    
        Set xl = CreateObject("Excel.Application")
        Set xlwbook = xl.Workbooks.Open(FilNam)
        Set xlsheet = xlwbook.Sheets.Item(1)
        xl.Visible = True 'Remove to hide the excel file
        
        Me.Text1 = xlsheet.range("A1") 'Do your work
        
        Set xl = Nothing
        Set xlwbook = Nothing
        Set xlsheet = Nothing

    End If

End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.