Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 361
Default VBA code to run macro in certain file based on name of file in cel

I am trying to come up with code that will run a macro in a workbook where
the path and name of the workbook are in a cell reference. I have tried the
following with no luck. The path to the file is located in cell F36 of
worksheet, "Customize" and the name of the file is located in cell F42. The
name of the macro is "ClearTotalSavings". Any help from one of you gurus
would sure be appreciated.

Application.Run "'" & Workbooks(Sheets("Customize").Range("F36").Value) &
"\" & Sheets("Customize").Range("F42").Value & "'!" & "ClearTotalSavings"

I use the following code to open a particular workbook using entries in the
same cells and it works just fine, so I know I am close. Thanks in advance.

Workbooks.Open Filename:="" & Sheets("Customize").Range("F36").Value & "\" &
Sheets("Customize").Range("F42").Value & "", _


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default VBA code to run macro in certain file based on name of file in cel

Hi Carl,

Try the following.

Application.Run "'" & Sheets("Customize").Range("F36").Value & _
"\" & Sheets("Customize").Range("F42").Value & "'!" & "ClearTotalSavings"


--
Regards,

OssieMac


"Carl" wrote:

I am trying to come up with code that will run a macro in a workbook where
the path and name of the workbook are in a cell reference. I have tried the
following with no luck. The path to the file is located in cell F36 of
worksheet, "Customize" and the name of the file is located in cell F42. The
name of the macro is "ClearTotalSavings". Any help from one of you gurus
would sure be appreciated.

Application.Run "'" & Workbooks(Sheets("Customize").Range("F36").Value) &
"\" & Sheets("Customize").Range("F42").Value & "'!" & "ClearTotalSavings"

I use the following code to open a particular workbook using entries in the
same cells and it works just fine, so I know I am close. Thanks in advance.

Workbooks.Open Filename:="" & Sheets("Customize").Range("F36").Value & "\" &
Sheets("Customize").Range("F42").Value & "", _


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default VBA code to run macro in certain file based on name of file in cel

Hi again Carl,

The code I posted before will work if the workbook containing the worksheet
Customize is the active workbook. Therefore I suggest that you might be
better to do it the following way to ensure that the code is addressing the
correct workbook with the sheet Customize.

Create the strPathFile first and ensure it is addressing the correct
workbook before using it in the run command.

Sub test()
Dim wb As Workbook
Dim strPathFile

'If not the workbook with the sub then
'set to whatever workbook has sheet Customize.
Set wb = ThisWorkbook

With wb.Sheets("Customize")

strPathFile = .Range("F36").Value _
& "\" & .Range("F42").Value

End With

Application.Run "'" & strPathFile & _
"'" & "!ClearTotalSavings"

End Sub

--
Regards,

OssieMac

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Retrieving Excel File extension based on XL File Format Enumeratio Sasikumar Kannappan Excel Programming 2 June 24th 09 03:59 PM
Create CSV file based on table in Excel file [email protected] Excel Programming 5 February 25th 08 08:22 AM
Can I use code/macro to change code/macro in an existing file? Scott Bedows Excel Programming 2 February 14th 07 05:50 AM
Seting a Constant (via code) when creating a new file based on a template Conan Kelly Excel Programming 1 July 15th 05 05:15 PM
Import VBA Code in Excel-File ? (Export VBA Code to file) Matthias Pospiech Excel Programming 2 March 22nd 05 04:56 PM


All times are GMT +1. The time now is 03:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"