MrIfOnly
Active Member
- Joined
- Nov 10, 2016
- Messages
- 497
Office365
Windows 11
I have a VBA program running as an Excel Add-in which deposits multiple shapes onto the user's worksheet. These shapes (for example, the two shown in the picture below labeled "Quality Check" and Undo Sort) use the .onaction property to run a macro that is located in a standard module in the add-in. Absolutely no code is stored in the user's workbook.
The shapes code is this:
This works just fine.
The problem arose from a user sending me a sheet with these shapes which work for him, but when I click on them I get an error message that reads "Sorry, Excel can't open two workbooks with the same name at the same time." followed by another message that reads: "Cannot run the macro "C:\Users\thchi\AppData\Roaming\Microsoft\AddIns\NozzleScheduleAutomation.xlam'!QualityCheck'. The macro may not be available in this workbook or all macros may be disabled."
The issue is that, when the onaction property is set to the shape, it is using the absolute path of the Add-in on the user's PC. So I tried to make this a relative path by trying:
and even trying to assign "Environ('APPDATA')" to a string variable and tacking it onto the .onaction code, to no avail.
You may have noticed that the above worksheet is opened from an Autocad drawing as an OLE, however my problem is repeatable on plain worksheets not attached to anything. Also, in order to test any variation to the code, I have to create the worksheet with the shapes on one PC and try to run them on a different PC with a different username.
If anybody has any ideas about how to make this work so that the program will run regardless of the PC it is run from, I would be eternally grateful.
TIA,
CJ
Windows 11
I have a VBA program running as an Excel Add-in which deposits multiple shapes onto the user's worksheet. These shapes (for example, the two shown in the picture below labeled "Quality Check" and Undo Sort) use the .onaction property to run a macro that is located in a standard module in the add-in. Absolutely no code is stored in the user's workbook.
The shapes code is this:
VBA Code:
If shapeexists("QLTYCHK") = False Then
With ActiveSheet.Shapes.ADDSHAPE(msoShapeRoundedRectangle, Range("K33").Left, Range("K33").Top, 150, 60)
.Name = "QLTYCHK"
.OnAction = "QualityCheck"
.Fill.ForeColor.RGB = RGB(305, 415, 0)
.Fill.BackColor.RGB = RGB(155, 285, 0)
.Fill.TwoColorGradient msoGradientHorizontal, 1
.Fill.Transparency = 0
With .TextFrame
.MarginBottom = 3
.MarginLeft = 10
.MarginRight = 10
.MarginTop = 3
.HorizontalAlignment = xlCenter
.Characters.Font.Color = vbBlue
.Characters.Font.Size = 19
.Characters.Font.Bold = True
.Characters.Text = "QUALITY CHECK"
End With
End With
End If
The problem arose from a user sending me a sheet with these shapes which work for him, but when I click on them I get an error message that reads "Sorry, Excel can't open two workbooks with the same name at the same time." followed by another message that reads: "Cannot run the macro "C:\Users\thchi\AppData\Roaming\Microsoft\AddIns\NozzleScheduleAutomation.xlam'!QualityCheck'. The macro may not be available in this workbook or all macros may be disabled."
The issue is that, when the onaction property is set to the shape, it is using the absolute path of the Add-in on the user's PC. So I tried to make this a relative path by trying:
VBA Code:
.OnAction = "'%APPDATA%\Roaming\Microsoft\AddIns\NozzleScheduleAutomation.xlam'!QualityCheck"
You may have noticed that the above worksheet is opened from an Autocad drawing as an OLE, however my problem is repeatable on plain worksheets not attached to anything. Also, in order to test any variation to the code, I have to create the worksheet with the shapes on one PC and try to run them on a different PC with a different username.
If anybody has any ideas about how to make this work so that the program will run regardless of the PC it is run from, I would be eternally grateful.
TIA,
CJ