Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy/Rename XLS and Macro References

Does anyone know how to have the Macros in my XLS file NOT have to reference
the orginal file position? I have created a toolbar button that runs a
macro. When I copy this XLS to another machine or rename the file, it can no
longer find the Macro since it is trying to find it in the original file.
The only way I can fix it is to "Assign Macro" again to the button. This is
not good as I need to distribute this XLS to other users. Is there a way
around this? The same problem occurs in the menus.

Thanks, -BOBJ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Copy/Rename XLS and Macro References

Hi,

1a. Create/Delete toolbar/menus/command bar buttons on the fly:
In the Workbook_Open sub of the ThisWorkbook module, create the toolbar,
menus, and controls using code.
In the Workbook_BeforeClose sub of the ThisWorkbook module, delete the
toolbar, menus, and controls.
Assign the macro using 2.
1b. For buttons on sheets directly, you can create them manually, then
assign the macro using 2.
2. Also, assign the proper OnAction property to controls based on the book
name when the book opens.
(Right after creating a control/button)
Something like:
Say your macro to be run is MyMacro
Dim macroName as String, cbb as commandbarbutton
macroName="MyMacro"
...
cbb.OnAction = "'" & thisworkbook.name & "'!" & macroname

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"BOBJ" wrote:

Does anyone know how to have the Macros in my XLS file NOT have to reference
the orginal file position? I have created a toolbar button that runs a
macro. When I copy this XLS to another machine or rename the file, it can no
longer find the Macro since it is trying to find it in the original file.
The only way I can fix it is to "Assign Macro" again to the button. This is
not good as I need to distribute this XLS to other users. Is there a way
around this? The same problem occurs in the menus.

Thanks, -BOBJ

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy/Rename XLS and Macro References

I find the easiest way is to create the toolbar when the workbook opens.


If you want to try...

If you want to add an option to the worksheet menu bar, I really like the way
John Walkenbach does it in his menumaker workbook:
http://j-walk.com/ss/excel/tips/tip53.htm

Here's how I do it when I want a toolbar:
http://groups.google.co.uk/groups?th...5B41%40msn.com

BOBJ wrote:

Does anyone know how to have the Macros in my XLS file NOT have to reference
the orginal file position? I have created a toolbar button that runs a
macro. When I copy this XLS to another machine or rename the file, it can no
longer find the Macro since it is trying to find it in the original file.
The only way I can fix it is to "Assign Macro" again to the button. This is
not good as I need to distribute this XLS to other users. Is there a way
around this? The same problem occurs in the menus.

Thanks, -BOBJ


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Copy/Rename XLS and Macro References

Hi,

1. Create menus, command bars on the fly with code.
a - when the book opens (in the Workbook_Open sub of the ThisWorkbook
module),
create the controls.
b - assign the macro to the contol with specific book name:
Dim macroName as String, cbb as CommandBarButton
...
cbb.OnAction = "'" & ThisWOrkbook.name & "'!" & macroName
c - Destroy the controls when the book closes (in the Workbook_BeforeClose
sub of the ThisWorkbook module).
2. For controls that are on a sheet, no need of creating/deleting through
code, just re-assign the macro throiugh code when the book opens (see 1b)

--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"BOBJ" wrote:

Does anyone know how to have the Macros in my XLS file NOT have to reference
the orginal file position? I have created a toolbar button that runs a
macro. When I copy this XLS to another machine or rename the file, it can no
longer find the Macro since it is trying to find it in the original file.
The only way I can fix it is to "Assign Macro" again to the button. This is
not good as I need to distribute this XLS to other users. Is there a way
around this? The same problem occurs in the menus.

Thanks, -BOBJ

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
Macro: Copy a worksheet and rename it to a specified value mitch Excel Discussion (Misc queries) 2 February 16th 09 05:43 PM
Copy, Paste and Rename a Range using a macro [email protected] Excel Discussion (Misc queries) 1 April 15th 08 03:58 PM
Macro REQ: Automatically copy a template sheet and rename MCSmarties Excel Worksheet Functions 5 October 11th 07 09:18 PM
How to rename references from range names to cell references Abbas Excel Discussion (Misc queries) 1 May 24th 06 06:18 PM
Run Macro & Rename Sheet upon creating copy from blank. Kervin Manasseh Excel Programming 1 October 14th 05 10:33 AM


All times are GMT +1. The time now is 01:10 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"