Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Message When Using a MACRO in Excel

Status
Not open for further replies.

wec43wec

Technical User
Aug 6, 2005
226
US
If the file name is "hard coded" in a macro, how do I create a macro within a file that can be used with a
different file name?

I had (still have) a problem with a macro that I created that references other macros on different sheets in a file that generates an error message each time I click or use this macro.

I was advised in another forum that the macro is hard coded and it generates an error if I file save the file with a different name. The only problem with this theory is that the single or individual macros that are used on one sheet does not seem to have a problem, only the macro that is references different macros on several sheets is the macro that I continue to have problems with.

Thanks for any assistance.
 
Hi wec43wec,

Well, depending on what you're doing, you might use 'Workbooks(Name)' - where you pass 'Name' as a variable, 'ActiveWorkbook' or 'ThisWorkbook'. It really depends on what you're trying to achieve.

Cheers

[MS MVP - Word]
 
Look in the object model. THISWORKBOOK can always be used to refer to the workbook in which the code resides. ACTIVEworkbook will refer to the workbook currently...well...active.....

The exact way around your issue can only be answered if you post some of the code that is bombing out and an explanation of what it is trying to achieve..

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
To interact with the user you can use FileDialog object (excel xp or higher) or older SaveAs dialog in Dialogs collection. A simple InputBox function can be used if there is no need to select the directory. In each case the input string should be validated (no '*' etc. inside).

combo
 
What about the Application.Run method ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top