943,657 Members | Top Members by Rank

Ad:
Oct 10th, 2007
0

open existing excel file in vba

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
six888 is offline Offline
6 posts
since Sep 2007
Oct 11th, 2007
0

Re: open existing excel file in vba

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
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: How to automatically update temperature on the form load?
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: which grid should I use





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC