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

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.