Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
can someone help me with the syntax of a macro? This does not seem to work.
sub Arbeitsblatt_Selektion
set sel = ActiveDocument.fields("__Kennzahl").GetSelectedValues
if sel.count = 0 then exit sub
Kategorie = sel.Item(0).text
if Kategorie = "OPC" then
Kategorie = "SH24"
else
if Kategorie = "Forecast" then
Kategorie = "SH04"
end if
ActiveDocument.Sheets(Kategorie).Activate
end sub
This has the purpose to open a specific worksheet in this app when the app is opened via document_chaining from a superposed management_dashboard. There is a failsafe for the case that the app is opened in the regular way.
(before I inserted the two or three lines in the "else" branch - when there was only the value "OPC" in the macro - it worked fine.
Thank you!
Best regards,
DataNibbler
Hi,
It looks like you are missing closing If
try this,
sub Arbeitsblatt_Selektion
set sel = ActiveDocument.fields("__Kennzahl").GetSelectedValues
if sel.count = 0 then exit sub
Kategorie = sel.Item(0).text
if Kategorie = "OPC" then
Kategorie = "SH24"
else
if Kategorie = "Forecast" then
Kategorie = "SH04"
end if
End if
ActiveDocument.Sheets(Kategorie).Activate
End sub
OR
You can do like this also,
sub Arbeitsblatt_Selektion
set sel = ActiveDocument.fields("__Kennzahl").GetSelectedValues
if sel.count = 0 then exit sub
Kategorie = sel.Item(0).text
if Kategorie = "OPC" then
Kategorie = "SH24"
ElseIf Kategorie = "Forecast" then
Kategorie = "SH04"
end if
ActiveDocument.Sheets(Kategorie).Activate
end sub
Regards,
Thanks!
I'll try that.
Hi max,
unfortunately it doesn't work yet.
The macro seems ok - clicking on the "check" button does not produce any error, anyway.
I have added one more ELSE to allow for the case that no button was pressed - but maybe that isn't necessary as in that case (meaning the app was opened in another way), there is a clause anyway? I don't know for sure.
I'll post the code here.
Can you help me there?
Thanks a lot!
Best regards,
DataNibbler
sub Arbeitsblatt_Selektion
set sel = ActiveDocument.fields("Kennzahl").GetSelectedValues
if sel.count = 0 then exit sub
Kategorie = sel.Item(0).text
if Kategorie = "OPC" then
Kategorie = "SH24"
elseif Kategorie = "Forecast" then
Kategorie = "SH04"
else
Kategorie = "SH01"
end if
ActiveDocument.Sheets(Kategorie).Activate
end sub
P.S.: I have now removed that extra ELSE branch (with the "SH01") since that case is accounted for by that EXIT clause at the beginning. Still it doesn't work: The selection (that text) is properly passed from the other app to this one, but the home_sheet opens, not the one I wanted.
P.P.S.: Since I don't know VB, I am m.o.l. guessing. I see there are two IF branches opened - one with the EXIT and then the big one. The big one is closed off properly - does the one with the EXIT need an END IF as well?