Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worksheets not viewable after xl.workbook.close #31

Open
afolson-NOAA opened this issue May 8, 2024 · 7 comments
Open

Worksheets not viewable after xl.workbook.close #31

afolson-NOAA opened this issue May 8, 2024 · 7 comments

Comments

@afolson-NOAA
Copy link

I have a script that opens a workbook, reads a range, runs a macro, then closes the workbook. The script works fine, but when I go to open the workbook in the Excel Application, none of the worksheets or worksheet tabs are visible. I know the workbook is loaded because the range name dropdown list in the toolbar shows the range names. If I try to open some other similar workbook I have, the worksheets are not visible. Based on some web searches I have discovered if I load an excel add-in (e.g. Solver), the worksheets become visible. Interestingly, I have also found that if I open R_connection_examples.xlsm before I open my workbook, all worksheets are visible.

Any ideas what could be going on? Is there a workaround I can automate in the workbook?

Thanks.

@afolson-NOAA
Copy link
Author

A simple workaround I have found is to include the following in the ThisWorkbook scope in VBA:

Private Sub Workbook_Open()
Sheets(1).Visible = True
End Sub

@gdemin
Copy link
Owner

gdemin commented May 13, 2024

Hi, @afolson-NOAA,
Could you provide a relevant part of the script which you are using? Does the script create these sheets or just modify existing sheets?

@afolson-NOAA
Copy link
Author

afolson-NOAA commented May 13, 2024 via email

@gdemin
Copy link
Owner

gdemin commented May 13, 2024

As far as I can see you don't create sheets. So it rather strange that visibility flag is changed for existing sheets. Can it be caused by macro 'B_Create_Input_File'?

@afolson-NOAA
Copy link
Author

afolson-NOAA commented May 13, 2024 via email

@gdemin
Copy link
Owner

gdemin commented May 13, 2024

Ok, if you will have additional details about this issue, keep me in touch. Currently I can't reproduce this behaviour.

@Siddharth-Latthe-07
Copy link

Here are some of the Possible Causes:

  1. Hidden Worksheets: Your script might be interacting with the workbook while some worksheets are hidden.
  2. Macro Behavior: The macro you're running within the script might be intentionally hiding worksheets for specific tasks.
  3. Corrupted Workbook: In rare cases, the workbook itself might be corrupted, causing issues with sheet visibility.

Unhide Worksheets: Before opening the workbook in Excel, use your script to unhide all worksheets.

VBA
Sub UnhideAllSheets()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
        ws.Visible = xlSheetVisible
    Next ws
End Sub
  1. Review Macro Code:

  2. Examine the macro code you're running for any lines that might be hiding worksheets. You might find code like ws.Visible = xlSheetHidden within specific sections. Modify the code to keep the worksheets visible after execution.

  3. Repair Workbook (Last Resort): If you suspect a corrupted workbook, right-click on the file in Explorer, go to Properties > Open With > Choose another app. Select "Microsoft Excel" and check the box "Always use this app to open .xlsx files." Click OK and try to open the workbook. Excel might attempt to repair it during the process.

Hope, this helps
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants