open existing excel file in vba

Reply

Join Date: Sep 2007
Posts: 6
Reputation: six888 is an unknown quantity at this point 
Solved Threads: 0
six888 six888 is offline Offline
Newbie Poster

open existing excel file in vba

 
0
  #1
Oct 10th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: open existing excel file in vba

 
0
  #2
Oct 11th, 2007
Hi,

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

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Command1_Click()
  2.  
  3. Dim xl
  4. Dim xlsheet
  5. Dim xlwbook
  6. Dim FilNam As String
  7.  
  8. Me.CommonDialog1.ShowOpen
  9. FilNam = Me.CommonDialog1.FileName
  10.  
  11. If Me.CommonDialog1.FileName <> "" Or Me.CommonDialog1.FileName <> ".xls" Then
  12.  
  13. Set xl = CreateObject("Excel.Application")
  14. Set xlwbook = xl.Workbooks.Open(FilNam)
  15. Set xlsheet = xlwbook.Sheets.Item(1)
  16. xl.Visible = True 'Remove to hide the excel file
  17.  
  18. Me.Text1 = xlsheet.range("A1") 'Do your work
  19.  
  20. Set xl = Nothing
  21. Set xlwbook = Nothing
  22. Set xlsheet = Nothing
  23.  
  24. End If
  25.  
  26. End Sub
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC