"Run application" based on condition...

  • Thread starter Thread starter J.W. Aldridge
  • Start date Start date
J

J.W. Aldridge

Hi.

Is there a way to add a condition before running an application?

For example, using the workbook open code below, I want to run the
application (hide_sheets) only IF applicable (only if the sheets are
hidden), otherwise bypass the command and do not give me a runtime
error.



Private Sub Workbook_Open()

Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"

MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")

End Sub



///////////Actual application///////////



Sub hide_sheets()
'
' hide_sheets Macro
'

'
Sheets(Array("ROSTER", "TIMESHEET", "PRODUCTION", "INFO
SHEET")).Select
ActiveWindow.SelectedSheets.Visible = False
End Sub
 
Hi.

Is there a way to add a condition before running an application?

For example, using the workbook open code below, I want to run the
application (hide_sheets) only IF applicable (only if the sheets are
hidden), otherwise bypass the command and do not give me a runtime
error.

Private Sub Workbook_Open()

Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"

MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")

End Sub

///////////Actual application///////////

Sub hide_sheets()
'
' hide_sheets Macro
'

'
Sheets(Array("ROSTER", "TIMESHEET", "PRODUCTION", "INFO
SHEET")).Select
ActiveWindow.SelectedSheets.Visible = False
End Sub

Hi,

can't you just use an error trap?

On Error Resume Next
'statements here
on error goto 0
 
Thanx...

Wasnt aware of that but I'll try installing that (although I am not
too familiar with that command - will play around with it until I get
it).
 
Ok... Been lookin everywhere for something to help me understand how
to work this code... Not sure. If someone can help me figure out where
to insert this and make it functional, I promise I will figure it out
from there.


On Error Resume Next
'statements here
on error goto 0


Private Sub Workbook_Open()
Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"
MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")
End Sub



Thanx
 
Private Sub Workbook_Open()
On Error Resume Next
Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"
On Error goto 0
MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")
End Sub
 
Ok... Been lookin everywhere for something to help me understand how
to work this code... Not sure. If someone can help me figure out where
to insert this and make it functional, I promise I will figure it out
from there.

On Error Resume Next
'statements here
on error goto 0

Private Sub Workbook_Open()
Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"
MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")
End Sub

Thanx

Hi mate,

sorry early in the morning, I should have been clearer.

Private Sub Workbook_Open()

on Error Goto skipit

Application.Run "'PCP DATA & PRODUCTION.xls'!hide_sheets"
MsgBox "Hello, welcome to PCP Data & Production" & Format(Date,
"ddd d mmm yyyy")

skipit:
End Sub

Note the On Error line with a GoTo, and then the Skipit: at the
bottom. Basically if an error is thrown, the lext line to be activated
is skipit:

Goto's aren't something you should use a lot, but I don't know there
is a choice here.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top