tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,924
- Office Version
- 365
- 2019
- Platform
- Windows
My workbook called SheetsTest.xlsm contains three worksheets and has the following code:
I can't see anything wrong with it but got an error trying to open it in the following way:
Can someone please try:
1. Create a workbook with the above code and save it.
2. E-mail it to yourself via outlook.
3. Open Excel and open any other SAVED Excel file.
4. Open the VB editor.
5. Open the attached Excel file in step2 DIRECTLY FROM OUTLOOK.
You should see a message about Protected view:
click Enable Editing.
Now because the VB editor is open, instead of a second message at the top, you should see a popup box, inviting you to Enable or Disable Macros.
Click Enable Macros.
I followed the above steps and got an error message:
and it failed on this line of the code:
Can someone explain why is that?
I googled and that error message is normally when you try to select something on a worksheet that is NOT the active worksheet.
I noticed there were two workbooks that were in the process of trying to be opened:
SheetsTest.xlsm (Read-Only) and SheetsTest.xlsm (Protected View).
Thanks
Code:
Option Explicit
Private Sub Workbook_Open()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
Set ws = Nothing
Sheet1.Select
End Sub
I can't see anything wrong with it but got an error trying to open it in the following way:
Can someone please try:
1. Create a workbook with the above code and save it.
2. E-mail it to yourself via outlook.
3. Open Excel and open any other SAVED Excel file.
4. Open the VB editor.
5. Open the attached Excel file in step2 DIRECTLY FROM OUTLOOK.
You should see a message about Protected view:
Code:
PROTETCED VIEW Be careful .....
click Enable Editing.
Now because the VB editor is open, instead of a second message at the top, you should see a popup box, inviting you to Enable or Disable Macros.
Click Enable Macros.
I followed the above steps and got an error message:
Code:
Run-time error '1004' Method 'Select' of object '_Worksheet failed.
and it failed on this line of the code:
Code:
Sheet1.Select
Can someone explain why is that?
I googled and that error message is normally when you try to select something on a worksheet that is NOT the active worksheet.
I noticed there were two workbooks that were in the process of trying to be opened:
SheetsTest.xlsm (Read-Only) and SheetsTest.xlsm (Protected View).
Thanks