Quote:
|
Originally Posted by Jim Wright
The problem I have is that when the button is pressed, the program comes up with an error "Cannot find Personal1.xls." (NOT Personal.xls). Can anyone tell me where the pointer to Personal.xls is stored and which appears to be correupted. I have copied Personal.xls to Personal1.xls with no joy. I have also scanned the Registry to no avail.
Any advice will be gratefully received, provided it reaches me before the men in white coats take me away (with apologies to Tom Lehrer !).
|
The way to avoid this problem is to create a separate toolbar with the buttons and macros assigned for your Personal.xls workbook (or whatever workbook containing your
VB Code) Then Attach this toolbar to the File following these steps: (1) make sure the file is visible. (2) Use Tools->Customize... Attach... (button) on the customize dialog. (3) Save the file with the attached custom toolbar.
(4) Place this code in the 'Workbook' class Module.
Save the workbook before closing.
Code:
' Replace 'CustTBName' with the actual Name used for your attached Custom Toolbar
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Toolbars("CustTBName").Delete
ThisWorkbook.Saved = True
End Sub
You may need to Hide the workbook first then save it (not sure if personal.xls will be hidden by default) Type 'Workbooks("Personal.xls").Save' in the Imediate window to save the hidden workbook after Hiding.
Now this way the toolbar buttons will not loose the workbook association even if you move the workbook or change the name. Further more if you send your client an updated workbook you will not need to consider deleting the old toolbar buttons or re-linking them. The Toolbar will be deleted each time the workbook is closed and will re-display whenever the book is opened.