web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Hide/Unhide sheets in ...
Power Automate
Answered

Hide/Unhide sheets in an already open excel file

(0) ShareShare
ReportReport
Posted on by 27

Hi team,

 

I am writing a flow like this:

Launch an excel file "Data_1"

runs a macro which refresh a certain table

Save and Close it

I have set a variable for timestamp.

Opens a second excel file "Report"

Run a macro which refresh a power Query reading data from the first excel file "Data_1"

 

In my excel file I have a hidden sheet named "SETTING" which I want the flow to unhide it, write in a certain cell the timestamp and hide again the sheet before saving it.

 

I am struggling to write the vb script to do that but the only thing I have found in the web is how to open and unhide all the sheets with the vb script. I Don't want that, I want to unhide a certain sheet from the already opened excel file.

 

What I have found is:

Set Variable ExcelFile and to the value is the excel path.

'Opens the Excel file'
Set objExcel = CreateObject("Excel.Application") Set objWorkbook = objExcel.Workbooks.Open("%ExcelFile%") objExcel.Application.Visible = True 'Unhides all the worksheets of the Excel file' For i=1 To objWorkbook.Sheets.Count objWorkbook.Sheets(i).Visible = True Next 'Saves and closes the Excel file' objWorkbook.Save objWorkbook.Close SaveChanges = True

 Any ideas?

 

Thank you in advance,

Eleftheria

  • OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    To unhide a specific sheet you can use the next VBA code:

    Sub UnhideSheet()

    Sheets("SETTING").Visible = True

    End Sub

     

    Good luck

  • EleftheriaK Profile Picture
    27 on at

    Thank you for your prompt reply. Your advise is to write a macro and not a vb script, right?

  • OkanMTL Profile Picture
    703 Super User 2024 Season 1 on at

    My bad,

     

    Use this for VB script:

    Set objWorksheet = objWorkbook.Worksheets("SETTING")

    objWorksheet.Visible = -1 'Set the sheet's Visible property to visible

     

    write this below the line:

    'Unhides all the worksheets of the Excel file'

    And inbetween:

    Next

     

    Good luck

  • EleftheriaK Profile Picture
    27 on at

    Thank you again for your response!

     

    You set the Dim objWorksheet but I don't see the set of objWorkbook. I tried it and is not working.

    objWorksheet.Visible = -1 the -1 means true?

    And how can I write the code for hiding the sheet?

    Thank you in advance,

    Eleftheria

  • Verified answer
    Kaif_Siddique Profile Picture
    2,108 Super User 2024 Season 1 on at

    Could you try the below VBScript? Added if condition to unhide Sheet2(sheet name) but customize it as per requirements.

     

    'Opens the Excel file'
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Open("%ExcelFile%")
    objExcel.Application.Visible = True

    'Unhides all the worksheets of the Excel file'
    For i=1 To objWorkbook.Sheets.Count
    if objWorkbook.Sheets(i).Name = "Sheet2" then
    objWorkbook.Sheets(i).Visible = True
    end if
    Next

     

    If I have answered your question, please mark my post as Solved.

    If you like my response, please give it a Thumbs Up.

     

    Regards

    Kaif

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 424

#2
11manish Profile Picture

11manish 328 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard