Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Excel and VB6


  • Please log in to reply
2 replies to this topic

#1 looney2340

looney2340

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:11:19 PM

Posted 03 February 2013 - 02:20 AM

Hi everyone,

It's been a very long time since i worked in vb6 im a beginner again. I am trying to open a specific excel file in vb6 with a command button. I need a simple code to do this. This is what i have but it doesnt open the file at C:\Users\Henry\desktop\project\test.xls it opens excel but not the file it just shows a grey screen an no workbook and the error msg box opens behind excel. BUT if i put the file on the desktop as C:\Users\Henry\desktop\test.xls it opens fine where am i going wrong? And can someone help me with a simple code to open a specific file ?

Thanks in advance


Private Sub Command2_Click()


On Error GoTo ErrHandler
Dim xlApp As Object
Dim xlWB As Object

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

Set xlWB = xlApp.Workbooks.Open("C:\Users\Henry\desktop\project\test.xls")
Exit Sub

ErrHandler:
MsgBox "There is a problem opening that workbook!", vbCritical, "Error!"

End Sub

Edited by looney2340, 03 February 2013 - 02:24 AM.


BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:19 PM

Posted 03 February 2013 - 09:40 AM

Check the permissions on your 'project' folder. Right click on the folder, select 'properties', and adjust the permissions so all users can get at the file.

#3 looney2340

looney2340
  • Topic Starter

  • Members
  • 202 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:NYC
  • Local time:11:19 PM

Posted 03 February 2013 - 10:30 AM

Thank you. I checked the permissions they are all fine. I found out what the error was. The path was good but when i right clicked and went to the properties of the actual text file it wasnt listed as .xls it was listed as .xlsx once i changed it it worked fine. So code looks like this now

Private Sub Cmdexcel_Click()


On Error GoTo ErrHandler
Dim xlApp As Object
Dim xlWB As Object

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True

Set xlWB = xlApp.Workbooks.Open("C:\Users\Henry\Desktop\Project\test.xlsx")
Exit Sub

ErrHandler:
MsgBox "There is a problem opening that workbook!", vbCritical, "Error!"

End Sub




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users