Hi,
I've been looking for a solution to this problem online and nothing seems to work so far.
I have a workbook that contains an ActiveX Command Button. Pressing this Button imports Data from another Database and updates everything on the sheet.
I then copy the information into another workbook, do some further calculations and create different Graphs out of this data.
I am trying to create a Code that automatically Presses the Command Button so as to update the data and then copy it into the other Workbook. I've been successful with the latter part.
Running the Command Button hasn't worked so far.
Below I added part of the code I'm using.
Any help would be very much appreciated.
Set current_wb = ThisWorkbook
Set sheet1 = current_wb.Sheets("Sheet1")
Set sheet2 = current_wb.Sheets("Sheet2")
Set sheet3 = current_wb.Sheets("Sheet3")
Set sheet4 = current_wb.Sheets("Sheet4")
current_wb.Activate
sheet1.Unprotect Password:="..."
path = "C:\Users\...\Book1.xlsm"
iwbo = BookOpen("Book1") 'This is a function that looks if the workbook is open in the workbooks directory of Excel
If iwbo = True Then
Set data_wb = Workbooks("Book1")
Else
Set data_wb = Workbooks.Open(path)
End If
data_wb.Sheets("Report1").Range("G1").Value = sheet1.Range("C2").Value
data_wb.Sheets("Report1").Range("A3").Value = "IPD"
data_wb.Sheets("Report1").Range("B3").Value = "D031"
Application.Run "Book1.xlsm!Sheet1.ForceCommandButton1"
At the moment I'm getting the following error message: "Run-time error '9': Subscript out of range"
When I take out the Application.Run Command the code runs great. When I try to run the Macro by opening the Macros Dialog box in the Developer and running it from there, I get the same error.
Bookmarks