Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Closing a workbook

Hi,

Can anyone help to make this work:

Sub CopyAndClose()
Dim filex
filex = Range("Sheets2!F2").Value
Workbooks.Open Filename:=filex, Password:="123"
Sheets("database").Select
Sheets("database").Copy Befo=Workbooks("test.xls"). _
Sheets(1)
Workbooks.Close Filename:=filex
End Sub

The error is in the last row.

Thanks, Gert-Jan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Closing a workbook

You will find it more easy to give yourself some variables to use.
dim WB as workbook

set wb=Workbooks.Open Filename:=filex, Password:="123"

'Don't what Workbooks("test.xls") refers to ?
Thisworkbook.Sheets("database").Copy Befo=Workbooks("test.xls").Sheets(1)
'Or do you mean
Thisworkbook.Sheets("database").Copy Befo=WB.Sheets(1)
'Or maybe, depending on which workbook contains the sheet "database"
WB.Sheets("database").Copy Befo=Thisworkbook.Sheets(1)
wb.close

NickHK

"Gert-Jan" wrote in message
...
Hi,

Can anyone help to make this work:

Sub CopyAndClose()
Dim filex
filex = Range("Sheets2!F2").Value
Workbooks.Open Filename:=filex, Password:="123"
Sheets("database").Select
Sheets("database").Copy Befo=Workbooks("test.xls"). _
Sheets(1)
Workbooks.Close Filename:=filex
End Sub

The error is in the last row.

Thanks, Gert-Jan




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Closing a workbook

That should read :
set wb=Workbooks.Open(Filename:=filex, Password:="123")

and
'Don't know what Workbooks("test.xls") refers to ?
Thisworkbook.Sheets("database").Copy

Befo=Workbooks("test.xls").Sheets(1)

NickHK

"NickHK" wrote in message
...
You will find it more easy to give yourself some variables to use.
dim WB as workbook

set wb=Workbooks.Open Filename:=filex, Password:="123"

'Don't what Workbooks("test.xls") refers to ?
Thisworkbook.Sheets("database").Copy

Befo=Workbooks("test.xls").Sheets(1)
'Or do you mean
Thisworkbook.Sheets("database").Copy Befo=WB.Sheets(1)
'Or maybe, depending on which workbook contains the sheet "database"
WB.Sheets("database").Copy Befo=Thisworkbook.Sheets(1)
wb.close

NickHK

"Gert-Jan" wrote in message
...
Hi,

Can anyone help to make this work:

Sub CopyAndClose()
Dim filex
filex = Range("Sheets2!F2").Value
Workbooks.Open Filename:=filex, Password:="123"
Sheets("database").Select
Sheets("database").Copy Befo=Workbooks("test.xls"). _
Sheets(1)
Workbooks.Close Filename:=filex
End Sub

The error is in the last row.

Thanks, Gert-Jan






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Closing a workbook

Hi Nick,

You have given the right solution, thanks a lot.

Best regards, Gert-Jan

"NickHK" schreef in bericht
...
That should read :
set wb=Workbooks.Open(Filename:=filex, Password:="123")

and
'Don't know what Workbooks("test.xls") refers to ?
Thisworkbook.Sheets("database").Copy

Befo=Workbooks("test.xls").Sheets(1)

NickHK

"NickHK" wrote in message
...
You will find it more easy to give yourself some variables to use.
dim WB as workbook

set wb=Workbooks.Open Filename:=filex, Password:="123"

'Don't what Workbooks("test.xls") refers to ?
Thisworkbook.Sheets("database").Copy

Befo=Workbooks("test.xls").Sheets(1)
'Or do you mean
Thisworkbook.Sheets("database").Copy Befo=WB.Sheets(1)
'Or maybe, depending on which workbook contains the sheet "database"
WB.Sheets("database").Copy Befo=Thisworkbook.Sheets(1)
wb.close

NickHK

"Gert-Jan" wrote in message
...
Hi,

Can anyone help to make this work:

Sub CopyAndClose()
Dim filex
filex = Range("Sheets2!F2").Value
Workbooks.Open Filename:=filex, Password:="123"
Sheets("database").Select
Sheets("database").Copy Befo=Workbooks("test.xls"). _
Sheets(1)
Workbooks.Close Filename:=filex
End Sub

The error is in the last row.

Thanks, Gert-Jan








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing a workbook N1KO Excel Discussion (Misc queries) 0 February 12th 09 03:51 PM
closing a workbook oercim Excel Programming 0 March 24th 06 01:27 PM
Closing Hidden Workbook when Active Workbook is Closed SusanK521 Excel Programming 5 September 24th 05 12:27 AM
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM


All times are GMT +1. The time now is 11:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"