Hi,
Problem, I wanted to consolidate my VBA so every button used the same macro.
The below doesn't seem to work when I use the variable ButtonText to call the custom view, but works fine if I type it manually, eg. "Total" which is one of the views I can to show.
I also tried the below which didn't work.
My work around was the below which works as I want it but it's more lines. Not the end of the world just like having short macros .
So, why don't the first 2 examples work?
Problem, I wanted to consolidate my VBA so every button used the same macro.
The below doesn't seem to work when I use the variable ButtonText to call the custom view, but works fine if I type it manually, eg. "Total" which is one of the views I can to show.
Code:
'Define variables
Dim ws As Worksheet: Set ws = ActiveSheet
Dim ButtonText As String
ButtonText = ws.Shapes(Application.Caller).TextFrame.Characters.Text
'Apply custom view - to pull print layout etc.
ThisWorkbook.CustomViews(ButtonText).Show
I also tried the below which didn't work.
Code:
ThisWorkbook.CustomViews.Item(ViewName:=ButtonText).Show
My work around was the below which works as I want it but it's more lines. Not the end of the world just like having short macros .
Code:
For Each CustomView In ThisWorkbook.CustomViews
If CustomView.Name = ButtonText Then
CustomView.Show
Exit For
End If
Next CustomView
So, why don't the first 2 examples work?