Understood @Sh99 , in that case you can use this code instead:
Keep in mind that you need to have a variable or use the Set Variable Action to have the workbook name %WorkBookName% and check the file suffix as well, here it was defined as “.xlsx”, so adjust as needed.
Option Explicit
Dim xlApp, xlBook, xlSheet
' Get a reference to the active Excel application
Set xlApp = GetObject(, "Excel.Application")
' Loop through all open workbooks
For Each xlBook In xlApp.Workbooks
If xlBook.Name = "%WorkBookName%" & ".xlsx" Then
' Set the active workbook
Set xlBook = xlApp.Workbooks("%WorkBookName%" & ".xlsx")
' Set the active sheet
Set xlSheet = xlBook.ActiveSheet
' Hide rows A15 to A17
xlSheet.Rows("15:17").EntireRow.Hidden = True
' Save the workbook (optional)
xlBook.Save
' Exit the loop since we found the workbook
Exit For
End If
Next
' Release the object references
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Hope this helps,
If I have addressed your inquiry successfully, kindly consider marking my response as the preferred solution. If you found my assistance helpful, a 'Thumbs Up' would be greatly appreciated.
Additionally, if you have any questions, feel free to DM me, and we can initiate a discussion.
Kind regards,
Will SG
Managing Director & Automation Lead
RAMS CR (Recruitment & Automation)
LinkedIn Profile