Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Workbooks.Close

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Workbooks.Close

Hard to comment only seeing the one line of code but that line you posted is
not correct. You are missing the colon.

Workbooks(cd).Close SaveChanges:= True

So that line you posted will not even execute... Perhpas post all of your
code so we can see what is going on...
--
HTH...

Jim Thomlinson


"andim" wrote:

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Workbooks.Close


I always use

set cd = workbooks.open(filename:=FName)

cd.close Savechanges:=true

Excel might not like CD because it is the command "Change Directory". Try a
different name!

"andim" wrote:

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Workbooks.Close

It was the colon missing that was the problem. Thanks very much. Here is all
of the code if you're interested.

Private Sub CommandButton3_Click()

Range("A20").Select
Selection.Copy
Workbooks.Open ("C:\Documents and Settings\Andrew\My Documents\Serious
Stuff\TCSpreadsheets\Convoluted.xls") 'Opens Convoluted
cd = ActiveWorkbook.Name ' Names Convoluted "cd" for closure later
ActiveSheet.Range("A20").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Workbooks(cd).Close SaveChanges:=True ' Closes Convoluted and saves (cd)

End Sub

Thanks again for your help I am very new to this and I am just basically
learning by recording macros and figuring out the code.

"Jim Thomlinson" wrote:

Hard to comment only seeing the one line of code but that line you posted is
not correct. You are missing the colon.

Workbooks(cd).Close SaveChanges:= True

So that line you posted will not even execute... Perhpas post all of your
code so we can see what is going on...
--
HTH...

Jim Thomlinson


"andim" wrote:

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Workbooks.Close

CD is the old DOS command.

ChDir is the VBA command to change directory.



Joel wrote:

I always use

set cd = workbooks.open(filename:=FName)

cd.close Savechanges:=true

Excel might not like CD because it is the command "Change Directory". Try a
different name!

"andim" wrote:

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,069
Default Workbooks.Close

this approach may do what you want.

Private Sub CommandButton3_Click()

Dim cd As Workbook
Dim rng1 As Range

Set rng1 = ActiveSheet.Range("A20")
Set cd = Workbooks.Open("C:\Documents and Settings\Andrew\My
Documents\SeriousStuff\TCSpreadsheets\Convoluted.x ls") 'Opens Convoluted

rng1.Copy cd.Worksheets("Sheet1").Range("A20") '<<change sheet name as
required
cd.Close True ' Closes Convoluted and saves

Application.CutCopyMode = False
End Sub
--
jb


"andim" wrote:

It was the colon missing that was the problem. Thanks very much. Here is all
of the code if you're interested.

Private Sub CommandButton3_Click()

Range("A20").Select
Selection.Copy
Workbooks.Open ("C:\Documents and Settings\Andrew\My Documents\Serious
Stuff\TCSpreadsheets\Convoluted.xls") 'Opens Convoluted
cd = ActiveWorkbook.Name ' Names Convoluted "cd" for closure later
ActiveSheet.Range("A20").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Workbooks(cd).Close SaveChanges:=True ' Closes Convoluted and saves (cd)

End Sub

Thanks again for your help I am very new to this and I am just basically
learning by recording macros and figuring out the code.

"Jim Thomlinson" wrote:

Hard to comment only seeing the one line of code but that line you posted is
not correct. You are missing the colon.

Workbooks(cd).Close SaveChanges:= True

So that line you posted will not even execute... Perhpas post all of your
code so we can see what is going on...
--
HTH...

Jim Thomlinson


"andim" wrote:

Hi everyone

I have a command button which takes the value of A20, opens another .xls
file and pastes the value in A20 of the new file (the new file has been
assigned to variable cd).

It is then supposed to close and save the new file with the following code:

Workbooks(cd).Close SaveChanges = True

But it doesn't save the changes. I don't know if it is because the command
button is in the first .xls file or not though.

Any Ideas?

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
workbooks close before OlieH Excel Programming 1 April 6th 08 08:40 AM
How to close All Workbooks Mervyn Thomas Excel Programming 1 December 28th 07 09:22 PM
why do all excel worksheets/workbooks close when I close one? Penny Excel Discussion (Misc queries) 1 November 29th 06 03:49 AM
close all other workbooks Rob Excel Programming 5 February 5th 06 08:44 PM
Close all other workbooks but this one? ianripping[_93_] Excel Programming 3 September 2nd 04 10:30 AM


All times are GMT +1. The time now is 11:46 PM.

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

About Us

"It's about Microsoft Excel"