Macro Conditions

R_J_Potter@msn.com

Registered User.
Local time
Today, 13:16
Joined
Nov 4, 2011
Messages
29
I’ve been using the following Macro “RunApp” coding in MS Access 2007 to open an Excel Worksheet.

Windows Vista
Action: RunApp
C:\Program Files\Microsoft Office\Office12\Excel.exe "C:\Users\Ron\Documents\MS\MS Excel97\Verizon .xlsm"

This Macro does what I want, But now I purchased a new Dell XPS laptop with Window 7 Professional (64 bit).

To get the Macro’s to work on the new laptop, I had to change the code that opens Excel from a different location C:\Program Files (x86). See below:

Windows 7 (64 BIT)
Action: RunApp
C:\Program Files (x86)\Microsoft Office\Office12\Excel.exe "C:\Users\Ron\Documents\MS\MS Excel97\Verizon .xlsm"

How can I add both Actions in the same Macro using a Condition Statement. i.e.
If file not found, goto next Action or Exit Macro

Open for suggestions to do it differently...
:banghead:
 
Add this code into a Module in your Database, set the Reference to use Excel via the Tools Menu and References in the VBA screen it will then do what you want on both machines. Then all you need to do is call the code behind a button on the form.

Sub openExcelBook()
'Set reference to use Excel
'Select the Tools Menu and References
'Search down the list for Microsoft Excel XX.Object Library

Dim ws As Excel.Application
Set ws = CreateObject("Excel.Application")
With ws
.Visible = True
.Workbooks.Open ("C:\Users\Ron\Documents\MS\MS Excel97\Verizon .xlsm")
End With


End Sub
 

Users who are viewing this thread

Back
Top Bottom