Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
 
Posts: n/a
Default Problem w/custom Macro Buttons on move to Laptop

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

First, back up files first!

But this seemed to work ok for me:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim cBarName As String
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"
cBarName = "yourtoolbarnamehere"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

Set cBar = Nothing
On Error GoTo 0
Set cBar = Application.CommandBars(cBarName)
On Error GoTo 0
If cBar Is Nothing Then
MsgBox "Missing commandbar named: " & cBarName
Exit Sub
End If

For Each ctrl In cBar.Controls
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf & ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name & Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
Next ctrl

End Sub

===========
But one way to avoid this problem is to build that toolbar when the workbook
opens (and delete it when the workbook closes.

This is how I do it:
http://groups.google.co.uk/groups?th...5B41%40msn.com



wrote:

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis


--

Dave Peterson
  #3   Report Post  
 
Posts: n/a
Default

Thanks for the code Dave, it's neat!

Unfortunately my macro buttons are spread out over many different command bars
so it would be just as easy to reassign the 20 macros by leaving the
Tools-Customize window up and right click on each macro icon and then assign
Macro to the Personal.xls!mymacro in the macro list box.

MS should have an easier way to do this.

Dennis


Dave Peterson wrote:

First, back up files first!

But this seemed to work ok for me:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim cBarName As String
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"
cBarName = "yourtoolbarnamehere"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

Set cBar = Nothing
On Error GoTo 0
Set cBar = Application.CommandBars(cBarName)
On Error GoTo 0
If cBar Is Nothing Then
MsgBox "Missing commandbar named: " & cBarName
Exit Sub
End If

For Each ctrl In cBar.Controls
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf & ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name & Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
Next ctrl

End Sub

===========
But one way to avoid this problem is to build that toolbar when the workbook
opens (and delete it when the workbook closes.

This is how I do it:
http://groups.google.co.uk/groups?th...5B41%40msn.com



wrote:

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis


  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

Maybe just cycling through all the commandbars would help:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

For Each cBar In Application.CommandBars
For Each ctrl In cBar.Controls
If ctrl.BuiltIn Then
'do nothing
Else
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf _
& ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name _
& Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
End If
Next ctrl
Next cBar

End Sub

==========
But I think the easiest solution would be to create the toolbars on the fly.
Then you won't have to go through the next time you upgrade.


wrote:

Thanks for the code Dave, it's neat!

Unfortunately my macro buttons are spread out over many different command bars
so it would be just as easy to reassign the 20 macros by leaving the
Tools-Customize window up and right click on each macro icon and then assign
Macro to the Personal.xls!mymacro in the macro list box.

MS should have an easier way to do this.

Dennis


Dave Peterson wrote:

First, back up files first!

But this seemed to work ok for me:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim cBarName As String
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"
cBarName = "yourtoolbarnamehere"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

Set cBar = Nothing
On Error GoTo 0
Set cBar = Application.CommandBars(cBarName)
On Error GoTo 0
If cBar Is Nothing Then
MsgBox "Missing commandbar named: " & cBarName
Exit Sub
End If

For Each ctrl In cBar.Controls
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf & ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name & Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
Next ctrl

End Sub

===========
But one way to avoid this problem is to build that toolbar when the workbook
opens (and delete it when the workbook closes.

This is how I do it:
http://groups.google.co.uk/groups?th...5B41%40msn.com



wrote:

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis


--

Dave Peterson
  #5   Report Post  
 
Posts: n/a
Default

Thanks again Dave. This code did it for all my macros.

Dennis

Dave Peterson wrote:

Maybe just cycling through all the commandbars would help:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

For Each cBar In Application.CommandBars
For Each ctrl In cBar.Controls
If ctrl.BuiltIn Then
'do nothing
Else
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf _
& ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name _
& Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
End If
Next ctrl
Next cBar

End Sub

==========
But I think the easiest solution would be to create the toolbars on the fly.
Then you won't have to go through the next time you upgrade.


wrote:

Thanks for the code Dave, it's neat!

Unfortunately my macro buttons are spread out over many different command bars
so it would be just as easy to reassign the 20 macros by leaving the
Tools-Customize window up and right click on each macro icon and then assign
Macro to the Personal.xls!mymacro in the macro list box.

MS should have an easier way to do this.

Dennis


Dave Peterson wrote:

First, back up files first!

But this seemed to work ok for me:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim cBarName As String
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"
cBarName = "yourtoolbarnamehere"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

Set cBar = Nothing
On Error GoTo 0
Set cBar = Application.CommandBars(cBarName)
On Error GoTo 0
If cBar Is Nothing Then
MsgBox "Missing commandbar named: " & cBarName
Exit Sub
End If

For Each ctrl In cBar.Controls
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf & ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name & Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
Next ctrl

End Sub

===========
But one way to avoid this problem is to build that toolbar when the workbook
opens (and delete it when the workbook closes.

This is how I do it:
http://groups.google.co.uk/groups?th...5B41%40msn.com



wrote:

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis




  #6   Report Post  
Dave Peterson
 
Posts: n/a
Default

It may have worked, but I'd still look at building the toolbar on the fly. It
really isn't that difficult and makes a lot simpler.

(Well, not simpler than being done--but you know what I mean <vbg.)

wrote:

Thanks again Dave. This code did it for all my macros.

Dennis

Dave Peterson wrote:

Maybe just cycling through all the commandbars would help:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

For Each cBar In Application.CommandBars
For Each ctrl In cBar.Controls
If ctrl.BuiltIn Then
'do nothing
Else
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf _
& ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name _
& Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
End If
Next ctrl
Next cBar

End Sub

==========
But I think the easiest solution would be to create the toolbars on the fly.
Then you won't have to go through the next time you upgrade.


wrote:

Thanks for the code Dave, it's neat!

Unfortunately my macro buttons are spread out over many different command bars
so it would be just as easy to reassign the 20 macros by leaving the
Tools-Customize window up and right click on each macro icon and then assign
Macro to the Personal.xls!mymacro in the macro list box.

MS should have an easier way to do this.

Dennis


Dave Peterson wrote:

First, back up files first!

But this seemed to work ok for me:

Option Explicit
Sub testme01()

Dim cBar As CommandBar
Dim cBarName As String
Dim ctrl As CommandBarControl
Dim newWkbk As Workbook
Dim newWkbkName As String
Dim ExclamePos As Long

newWkbkName = "Personal.xls"
cBarName = "yourtoolbarnamehere"

Set newWkbk = Nothing
On Error Resume Next
Set newWkbk = Workbooks(newWkbkName)
On Error GoTo 0
If newWkbk Is Nothing Then
MsgBox "Please open the new " & newWkbkName & " file!"
Exit Sub
End If

Set cBar = Nothing
On Error GoTo 0
Set cBar = Application.CommandBars(cBarName)
On Error GoTo 0
If cBar Is Nothing Then
MsgBox "Missing commandbar named: " & cBarName
Exit Sub
End If

For Each ctrl In cBar.Controls
If InStr(1, ctrl.OnAction, newWkbkName, vbTextCompare) 0 Then
Debug.Print "----" & ctrl.Caption & "----" & vbLf & ctrl.OnAction
ExclamePos = InStr(1, ctrl.OnAction, "!")
If ExclamePos 0 Then
ctrl.OnAction = newWkbk.Name & Mid(ctrl.OnAction, ExclamePos)
End If
Debug.Print ctrl.OnAction
End If
Next ctrl

End Sub

===========
But one way to avoid this problem is to build that toolbar when the workbook
opens (and delete it when the workbook closes.

This is how I do it:
http://groups.google.co.uk/groups?th...5B41%40msn.com



wrote:

In Excel 2000 on my WinXP Pro computer I had custom macro buttons that when
clicked executed the VBA code in my personal.xls file. The excel.xlb was
located in c:\Documents and Setting\comp1\Application Data\Excel and the
personal.xls file was located in "c:\Documents and Setting\comp1\Application
Data\Excel\Xlstart".

On my new laptop with Win XP Home I reinstalled Excel 2000 and put the
excel.xlb file in c:\Documents and Setting\Laptop\Application Data\Excel and put
the personnal.xls file into c:\Documents and Setting\Laptop\Application
Data\Excel\Xlstart

On the laptop when I bring Excel up the custom macro buttons are there
and the personal.xls file is loaded ( I can see it in the Visual Basic Editor).

However when I click on a custom macro button I get the following error:
"A document with the name personal.xls is already open. You cannot open two
documents with the same name even if the documents are in different folders."

I did a search on the whole disk and there is only one file named personal.xls
and it is located as above.

If I click on Tools-Customize-right click the macro icon-assign Macro. The
Assign Macro Window appears with the macro name c:\Documents and
Setting\comp1\Application Data\Excel\Xlstart\Personal.xls!mymacro

If I reassign the custom button to that same macro that shows up in the window
list below the Macro Name which shows the name Personal.XLS!mymacro, than that
custom macro button works fine after I close and reopen Excel while the other
custom buttons still won't work.

Since I have about 20 custom buttons assigned to 20 different VBA macros it
would be cumbersome to reassign each button.

Is there an easier way to redirect all the custom macro buttons to
Personal.XLS!?

Thanks for any help.

Dennis


--

Dave Peterson
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
URGENT Mac/PC macro compatibility problem marika1981 Excel Discussion (Misc queries) 7 January 8th 05 12:43 AM
Macro - - Automation Jac Excel Discussion (Misc queries) 8 December 27th 04 02:42 PM
macro problem Kevin Excel Discussion (Misc queries) 1 December 14th 04 10:47 PM
Macro Problem Kevin Excel Discussion (Misc queries) 1 December 9th 04 06:55 PM
Import chart to Power Point and Macro problem Woody13 Excel Discussion (Misc queries) 1 December 8th 04 05:47 PM


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