Open a specific Excel file

  • Thread starter Thread starter JudithJubilee
  • Start date Start date
J

JudithJubilee

Hello All,

I woul;d like to have buttons on an Access form that open
speific Excel files, even if possible to open at named
ranges. I can add a button to Open Excel but that is the
default. I know how to add hyperlinks also.

Can I have buttons or am I to stick with hyperlinks?

Thank you in advance

JudithJubilee
 
Here's some sample code for opening an EXCEL workbook I
aquired from previous posts:
In a macro for the RunApp action on the command line put
one of the 2. Watch for word wrap.
Syntax
="path to excel executable" "path to file name"
ex.
="C:\program files\Microsoft Office\Office\excel.exe _
\\corpserver\sales\final documents\office space document.xls"
or
="C:\program files\Microsoft Office\Office\excel.exe" _
"\\corpserver\sales\final documents\office space document.xls"

or in code

Public Sub TestMacroRun()
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Set xlx = CreateObject("Excel.Application")
xlx.Visible = True
Set xlw = xlx.workbooks.Open("C:\Filename.xls")
Set xls = xlw.Worksheets("WorksheetName")
Set xlc = xls.Range("A1")
' put code here to write into the cells etc.
' .
' .
' .
Set xlc = Nothing
Set xls = Nothing
xlw.Save
xlw.Close False
Set xlw = Nothing
xlx.Quit
Set xlx = Nothing
End Sub

Chris
 
Hi,
You can have buttons.
Using the runapp method in an access macro. here is one i
use to open a specific file.
all you have to do is add the file path to the file
C:\Program files\Office2k\office\Excel.exe
H:\codestuff\excelmacros.xls
Caution: file path line wrapped. suppost to be one line.
leave a space between the 2 file paths.
Caution: this will open xl a second time
to go to a range in excel, just put a goto statement in
the excel file's on open event. something like this
Application.Goto Reference:="myrange"

Using VB
Private Sub cmdOpenXL_Click()

Dim xlx As Object, xlw As Object, xls As Object
On Error Resume Next
Set xlx = GetObject(, "Excel.Application")
If Err.Number <> 0 Then Set xlx = CreateObject
("Excel.Application")
' Comment out the next line if you don't want EXCEL to
be "seen" by user
xlx.Visible = True
Set xlw = xlx.workbooks.Open("H:\LocLotDiff.xls")
'Set xls = xlw.Worksheets("WorksheetName")

xlx.Goto Reference:="xlLotLocDiff"
'appXL.Run ("sDriver") ' run the excel macro

'appXL.ActiveWorkbook.Save
'appXL.Quit

End Sub
this method will not open xl a second time.
good luck
 
Back
Top