Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

This is the code I am using to open another excel file, copy data an
paste it into the original file. Is it possible to add a line in thi
macro that will do a saveas on the original workbook (ThisWB)? I woul
like to do a saveas with the name of the other file (OpenedWB) and "-F
for Finished.

So, ThisWB would have a saveas with the name being "OpenedWB - F".

Sub testIt()
Dim ThisWB As Workbook, OpenedWB As Workbook, _
OpenFileName As Variant
Set ThisWB = ThisWorkbook
OpenFileName = Application.GetOpenFilename()
If LCase(TypeName(OpenFileName)) = "boolean" Then
Else
Set OpenedWB = Workbooks.Open(OpenFileName)
OpenedWB.Sheets(1).Range("A1:Z100").Copy
ThisWB.Worksheets("sheet1").Range("b1").PasteSpeci al _
xlPasteValuesAndNumberFormats
OpenedWB.Close False
End If
End Sub


Thank you

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

I am not sure if I described this sufficiently...

Using sample names,

Workbook1 = Music
Workbook2 = Animal


Using a macro in "Music", I would like to access the file name in
"Animal" and do a saveas on the Music File. The result is three
files...

"Music"
"Animal"
"Animal - F"

Hope that helps


---
Message posted from http://www.ExcelForum.com/

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

I am finding this somewhat difficult to explain. Ok, one more time.

Starting with the "Music" file I run the macro

The macro accesses "Animal" file, copies some of the data and pastes i
to the "Music" File


Next, I would like the updated "Music" File to be saved as "Animal - F
(or what ever the name of the accessed file, adding "- F" to the end)


Any ideas

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

Is this right??

ActiveWorkbook.SaveAs FileName:="OpenedWB - F"


Also, how would I designate a specific directory for the save?



Thanks

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Saveas with name of another file

Hi
use ChDir
prior to saving the file

--
Regards
Frank Kabel
Frankfurt, Germany


Is this right??

ActiveWorkbook.SaveAs FileName:="OpenedWB - F"


Also, how would I designate a specific directory for the save?



Thanks.


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

A little uniformed on this,....can you be more specific on how to d
this.

I am a Senior Forum member only because I ask sooo many questions!!
just became interested in the VB code and found a lot of applications.
The problem is I only have enough programming skill to be dangerous.


Thanks

--
Message posted from http://www.ExcelForum.com

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Saveas with name of another file

Hi
e.g.
sub foo()
chdrive "C:\"
chdir "C:\temp"
ActiveWorkbook.SaveAs FileName:="OpenedWB - F"
end sub

--
Regards
Frank Kabel
Frankfurt, Germany


A little uniformed on this,....can you be more specific on how to do
this.

I am a Senior Forum member only because I ask sooo many questions!!

I
just became interested in the VB code and found a lot of

applications.
The problem is I only have enough programming skill to be dangerous.


Thanks.


---
Message posted from http://www.ExcelForum.com/


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

Thansk, Frank!

That got me all the way there, but with the wrong file name. I don'
think it was explained right...

OpenedWB is a variable name for whatever the file I am opening is.
don't want to do as saveas with literally "OpenedWB". It should be
for example, "5-18-04 - F". Where OpenedWB, in this case, i
5-18-04.xl

--
Message posted from http://www.ExcelForum.com

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

When I put this coede at the end of the sequence, is OpenWB no longer a
active variable

--
Message posted from http://www.ExcelForum.com

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Saveas with name of another file

Hi
now you have lost me :-)


--
Regards
Frank Kabel
Frankfurt, Germany


Thansk, Frank!

That got me all the way there, but with the wrong file name. I don't
think it was explained right...

OpenedWB is a variable name for whatever the file I am opening is. I
don't want to do as saveas with literally "OpenedWB". It should be,
for example, "5-18-04 - F". Where OpenedWB, in this case, is
5-18-04.xls


---
Message posted from http://www.ExcelForum.com/




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

This is the code that I am using...

Sub testIt()
Dim ThisWB As Workbook, OpenedWB As Workbook, _
OpenFileName As Variant
Set ThisWB = ThisWorkbook
OpenFileName = Application.GetOpenFilename()
If LCase(TypeName(OpenFileName)) = "boolean" Then
Else
Set OpenedWB = Workbooks.Open(OpenFileName)
OpenedWB.Sheets(1).Range("A1:Z100").Copy
ThisWB.Worksheets("sheet1").Range("b1").PasteSpeci al _
xlPasteValuesAndNumberFormats
OpenedWB.Close False
End If
End Sub


When I run the macro, the open file window appears and I choose a fil
(Variable name = OpenedWB), the data is copied from the "Opene
Workbook" and pasted into the the original workbook (Variable name
ThisWB).

I want to add a code at the end that resaves "ThisWB", naming i
Animal, Music, or whatever the opened workbook was called. I woul
like to get the filename from the opened workbook and use it as th
filename for the original workbook.


Does that help at all

--
Message posted from http://www.ExcelForum.com

  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Saveas with name of another file

Hi
try
Sub testIt()
Dim fname
Dim ThisWB As Workbook, OpenedWB As Workbook, _
OpenFileName As Variant
Set ThisWB = ThisWorkbook
OpenFileName = Application.GetOpenFilename()
If LCase(TypeName(OpenFileName)) = "boolean" Then
Else
Set OpenedWB = Workbooks.Open(OpenFileName)
OpenedWB.Sheets(1).Range("A1:Z100").Copy
ThisWB.Worksheets("sheet1").Range("b1").PasteSpeci al _
xlPasteValuesAndNumberFormats

fname = OpenedWb.name
OpenedWB.Close False
End If

ThisWb.saveas fname


End Sub


--
Regards
Frank Kabel
Frankfurt, Germany


This is the code that I am using...

Sub testIt()
Dim ThisWB As Workbook, OpenedWB As Workbook, _
OpenFileName As Variant
Set ThisWB = ThisWorkbook
OpenFileName = Application.GetOpenFilename()
If LCase(TypeName(OpenFileName)) = "boolean" Then
Else
Set OpenedWB = Workbooks.Open(OpenFileName)
OpenedWB.Sheets(1).Range("A1:Z100").Copy
ThisWB.Worksheets("sheet1").Range("b1").PasteSpeci al _
xlPasteValuesAndNumberFormats
OpenedWB.Close False
End If
End Sub


When I run the macro, the open file window appears and I choose a

file
(Variable name = OpenedWB), the data is copied from the "Opened
Workbook" and pasted into the the original workbook (Variable name =
ThisWB).

I want to add a code at the end that resaves "ThisWB", naming it
Animal, Music, or whatever the opened workbook was called. I would
like to get the filename from the opened workbook and use it as the
filename for the original workbook.


Does that help at all?


---
Message posted from http://www.ExcelForum.com/


  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

That's what I was looking for.


THANK YOU, Frank

--
Message posted from http://www.ExcelForum.com

  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

Trying to modify the saved name just slightly...

How do I remove the .xls??


ThisWB.SaveAs fname & " - F

--
Message posted from http://www.ExcelForum.com

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Saveas with name of another file

Figured it out...


fname = Left(OpenedWB.Name, Len(OpenedWB.Name) - 4)


Thanks

--
Message posted from http://www.ExcelForum.com



  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Saveas with name of another file

Hi
another option: use replace for this

--
Regards
Frank Kabel
Frankfurt, Germany


Trying to modify the saved name just slightly...

How do I remove the .xls??


ThisWB.SaveAs fname & " - F"


---
Message posted from http://www.ExcelForum.com/

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
Can you Pre-fill file name in SaveAs dialog Jive Excel Worksheet Functions 1 November 12th 07 04:30 PM
Confused here Prevent Saving File - but allow ONLY File SAVEAS Met JMay Excel Discussion (Misc queries) 2 June 17th 07 04:37 PM
saveas CSV file stevekirk Excel Discussion (Misc queries) 0 August 10th 06 01:11 PM
SaveAs another file name, then keep working L Mehl Excel Programming 2 February 24th 04 02:11 AM
VBA capture File SaveAs Event Linda Mcfarlane Excel Programming 2 September 17th 03 04:06 AM


All times are GMT +1. The time now is 02:50 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"