I found some code that will allow me to import a module into a workbook from a network folder. However when I try to use my VBA code to assign a macro to an autoshape it is trying to look for the macro in the original workbook not the new one where the macro resides.
Here is the code that I am using.
Any suggestions on how I can get it to point to the macro in the newly imported module?
Here is the code that I am using.
Code:
sub test()
InsertVBComponent ActiveWorkbook, "R:\SPC Log\SPC_Module.bas"
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 228#, 557.25, 126#, 13.5).Select
With Selection
.Width = 110
.Height = 18
.Top = Range("D34").Top
.Left = Range("D34").Left
.Characters.Text = "Click to Insert Name"
.ShapeRange.Fill.Visible = msoTrue
.ShapeRange.Fill.ForeColor.SchemeColor = 43
.ShapeRange.Line.Visible = msoTrue
.ShapeRange.Line.ForeColor.SchemeColor = 64
.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
.Name = "Prepared_by_box"
.OnAction = "Prepared_by_box"
End With
end sub
Sub InsertVBComponent(ByVal wb As Workbook, ByVal CompFileName As String)
If Dir(CompFileName) <> "" Then
On Error Resume Next
wb.VBProject.VBComponents.Import CompFileName
On Error GoTo 0
End If
Set wb = Nothing
End Sub
Any suggestions on how I can get it to point to the macro in the newly imported module?
Last edited: