The macro below is supposed to assign an existing macro in each workbook to the form control button. The existing macro is called "Mail_Sheet_Outlook_Body". However, when I open the workbooks, the button is actually pointing to the "Assign_Button" macro in my c:drive, it's not pointing to the Mail_Sheet_Outlook_Body macro that's actually in the workbook. So, when the button is clicked, it gives an error and tries to open the "Assign_Button" file from the c:drive.
Any suggestions or help is appreciated! Thanks!
Any suggestions or help is appreciated! Thanks!
Code:
Sub Assign_Button()
Dim FolderPath As String
Dim FileName As String
Dim wbThisWorkBk As Workbook
Dim wbThisWB As Workbook
Set wbThisWB = ActiveWorkbook
Application.ScreenUpdating = False
FolderPath = "c:\users\documents\Test\"
FileName = Dir(FolderPath & "*.xl*")
Do While FileName <> ""
Set wbThisWB = Workbooks.Open(FolderPath & FileName)
Worksheets("USD").Buttons("Button 1").OnAction = "Mail_Sheet_Outlook_Body"
Range("A2").Select
wbThisWB.Close savechanges:=True
FileName = Dir()
Loop
Application.ScreenUpdating = True
MsgBox ("Done!")
End Sub