Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Visual Basic Code in Access

 

I need some help in Microsoft Access. I have a command button on my form that I want to open an existing Microsoft Excel file. I've been trying to write visual basic code to activate this file. Is their away to do this?

 

 

Thank You,

Edited by Art Collins
Posted
Have you tried using a command line arguement? System.Diagnostics.Process.Start("excel.exe"' date=' "myFile.xls")[/quote']

 

Can you give me an example on how that would be written in Visual Basic.

 

Thank you,

Posted

I havent used Access in a while but, doesnt the normal wizard that appears when you add a button on a form in Access, give you an option to start Excel. Try running that wizard and look at what it generates, that should do the trick I think.

 

OK, here is the code that is generated by the wizard:

On Error GoTo Err_Command0_Click

   Dim oApp As Object

   Set oApp = CreateObject("Excel.Application")
   oApp.Visible = True
   'Only XL 97 supports UserControl Property
   On Error Resume Next
   oApp.UserControl = True

Exit_Command0_Click:
   Exit Sub

Err_Command0_Click:
   MsgBox Err.Description
   Resume Exit_Command0_Click

 

That seems to start Excel through automation, but doesnt load a file yet. But loading a file should be something that is available on the oApp object I think.

Nothing is as illusive as 'the last bug'.
  • 2 weeks later...
Posted
I havent used Access in a while but, doesnt the normal wizard that appears when you add a button on a form in Access, give you an option to start Excel. Try running that wizard and look at what it generates, that should do the trick I think.

 

OK, here is the code that is generated by the wizard:

On Error GoTo Err_Command0_Click

   Dim oApp As Object

   Set oApp = CreateObject("Excel.Application")
   oApp.Visible = True
   'Only XL 97 supports UserControl Property
   On Error Resume Next
   oApp.UserControl = True

Exit_Command0_Click:
   Exit Sub

Err_Command0_Click:
   MsgBox Err.Description
   Resume Exit_Command0_Click

 

That seems to start Excel through automation, but doesnt load a file yet. But loading a file should be something that is available on the oApp object I think.

 

Thanks for the code.

I still can't open a excel file, any suggestions.

Posted
Does it give any errors or just not work? What code have you got so far?

 

On Error GoTo Err_Command0_Click

 

Dim oApp As Object

 

Set oApp = CreateObject("Excel.Application")

oApp.Visible = True

'Only XL 97 supports UserControl Property

On Error Resume Next

oApp.UserControl = True

 

Exit_Command0_Click:

Exit Sub

 

Err_Command0_Click:

MsgBox Err.Description

Resume Exit_Command0_Click

 

 

This opens excel only.

 

I've tried oApp = getobject and the path where the file is located.

 

The top line of the excel file flashes on the screen. Then the error comes up saying Object dosen't support this property method.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...