Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have a workbook that will always contain at least one visible worksheet.
The number of visible worksheets may vary, but the workbook will always contain at least one visible and one hidden worksheet. I would like to add the following logic to run with an on open workbook event but am having a hard time piecing together the proper VB code. On Workbook Open, For each visible worksheet within the workbook, IF cell A1="Input", THEN run formatting macro, ELSE do nothing. Any help is much appreciated. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mike, test each worksheet to see if it is visible:
Private Sub Workbook_Open() Dim ws As Worksheet For Each ws In ThisWorkbook.Worksheets If ws.Visible = xlSheetVisible Then If ws.Range("A1") = "Input" Then formatting_macro End If End If Next End Sub replace "formatting_macro" with the name of your macro -- Charles Chickering "A good example is twice the value of good advice." "Mike G - D.C." wrote: I have a workbook that will always contain at least one visible worksheet. The number of visible worksheets may vary, but the workbook will always contain at least one visible and one hidden worksheet. I would like to add the following logic to run with an on open workbook event but am having a hard time piecing together the proper VB code. On Workbook Open, For each visible worksheet within the workbook, IF cell A1="Input", THEN run formatting macro, ELSE do nothing. Any help is much appreciated. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
give this a try... It must go into the thisworkbook module. Right click the
XL icon next to the word file in the XL menu and select View Code. Paste the following Private Sub Workbook_Open() Dim wks As Worksheet For Each wks In Worksheets If wks.Visible = xlSheetVisible Then MsgBox "Format sheet " & wks.Name End If Next wks End Sub Not that this code is not activating the sheet... -- HTH... Jim Thomlinson "Mike G - D.C." wrote: I have a workbook that will always contain at least one visible worksheet. The number of visible worksheets may vary, but the workbook will always contain at least one visible and one hidden worksheet. I would like to add the following logic to run with an on open workbook event but am having a hard time piecing together the proper VB code. On Workbook Open, For each visible worksheet within the workbook, IF cell A1="Input", THEN run formatting macro, ELSE do nothing. Any help is much appreciated. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry I missed the whole A1 = Input thing ... Try this...
Private Sub Workbook_Open() Dim wks As Worksheet For Each wks In Worksheets If wks.Visible = xlSheetVisible And _ UCase(wks.Range("A1").Value) = "INPUT" Then MsgBox "Format sheet " & wks.Name 'wks.select 'Select the sheet if necessary End If Next wks End Sub -- HTH... Jim Thomlinson "Jim Thomlinson" wrote: give this a try... It must go into the thisworkbook module. Right click the XL icon next to the word file in the XL menu and select View Code. Paste the following Private Sub Workbook_Open() Dim wks As Worksheet For Each wks In Worksheets If wks.Visible = xlSheetVisible Then MsgBox "Format sheet " & wks.Name End If Next wks End Sub Not that this code is not activating the sheet... -- HTH... Jim Thomlinson "Mike G - D.C." wrote: I have a workbook that will always contain at least one visible worksheet. The number of visible worksheets may vary, but the workbook will always contain at least one visible and one hidden worksheet. I would like to add the following logic to run with an on open workbook event but am having a hard time piecing together the proper VB code. On Workbook Open, For each visible worksheet within the workbook, IF cell A1="Input", THEN run formatting macro, ELSE do nothing. Any help is much appreciated. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro to create a shortcut to make next Worksheet visible | Excel Programming | |||
Worksheet has to set to visible as it is not visible after saving and closing Excel by VB. | Excel Programming | |||
print different worksheet by pressing visible button on worksheet | Excel Worksheet Functions | |||
Macro for Hiding Visible Worksheet | Excel Programming | |||
Macro to enable or visible on specific worksheet only | Excel Programming |