Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object variable Excel

Status
Not open for further replies.

Mollethewizard

IS-IT--Management
Nov 18, 2002
93
0
0
SE
This maybe very simple – but anyway – I’ve got a workbook with a modeless user form with a button that closes this particular workbook. Code goes like this:

Application.ActiveWorkbook.Close Savechanges:=False

That’s all right providing the workbook is activated. Is there a simple way to assign the workbook to a variable when the workbook opens that I can call later regardless what workbook is activated at the moment I press the button on the user form?

Something with an object-variable I presume...

Could someone help, please?

Mollethewizard
 
Have a look at the ThisWorkbook on open event.

Chance,

Filmmaker, taken gentleman and [insert quote here]
 
Chance

Talking of idiotic questions….

ThisWorkbook.Close savechanges:= False

Did the trick regardless how many other workbooks there were open.

Thanks for putting me on the right track!

Mollethewizard
 


Hi,

You might have multiple workbooks open. Each open workbook has a ThisWorkbook Object.

You could assign an Object Variable like...
Code:
  Dim wb1 as workbook

  Set wb1 = workbooks.add  ' or Open method

...

  wb1.close
  set wb1 = nothing


Skip,
[sub]
[glasses] [red]Be Advised![/red] The Vinyards of Texas have produced a wine with diuretic dimishment and urethric relief...
Pinot More![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top