Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
KingKarl
 
Posts: n/a
Default Name file automatically

I'm struggling with a problem that I bet is easy as ****, but anyway...

I want to make a macro that saves only sheet number five (named "giro") of
my workbook, and at the same time gives the file the name of the value of
cell Q1 and cell B9 on this sheet. Is this possible?

Thanx a lot in advance...
  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'm not sure what you have in Q1 and B9, but maybe...

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveWorkbook.Worksheets("giro")

wks.Copy 'to a new workbook

With ActiveSheet
.Parent.SaveAs Filename:="C:\" _
& .Range("q1").Value & .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal
.Parent.Close savechanges:=False
End With

End Sub

There is no error checking -- make sure those values in Q1 and B9 will make a
nice name.

(Dates are problems. Windows files can't have /'s in them.)

.Parent.SaveAs Filename:="C:\" _
& format(.Range("q1").Value, "yyyy_mm_dd") _
& .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal

Might work for you.

KingKarl wrote:

I'm struggling with a problem that I bet is easy as ****, but anyway...

I want to make a macro that saves only sheet number five (named "giro") of
my workbook, and at the same time gives the file the name of the value of
cell Q1 and cell B9 on this sheet. Is this possible?

Thanx a lot in advance...


--

Dave Peterson
  #3   Report Post  
KingKarl
 
Posts: n/a
Default

Thanx a lot...

This worked fine. I only had to add the line in the macro that tells it to
print :-)

Still, after using this I encoutered another problem: when opening the saved
file and having the original workbook open, the saved file automatically
updated itself with the latest cell values (because alle the cells in "giro"
are linked to another sheet in the workbook). Is there a way to get around
this problem?

Karl Erik Kvalsund

Dave Peterson skrev:

I'm not sure what you have in Q1 and B9, but maybe...

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveWorkbook.Worksheets("giro")

wks.Copy 'to a new workbook

With ActiveSheet
.Parent.SaveAs Filename:="C:\" _
& .Range("q1").Value & .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal
.Parent.Close savechanges:=False
End With

End Sub

There is no error checking -- make sure those values in Q1 and B9 will make a
nice name.

(Dates are problems. Windows files can't have /'s in them.)

.Parent.SaveAs Filename:="C:\" _
& format(.Range("q1").Value, "yyyy_mm_dd") _
& .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal

Might work for you.

KingKarl wrote:

I'm struggling with a problem that I bet is easy as ****, but anyway...

I want to make a macro that saves only sheet number five (named "giro") of
my workbook, and at the same time gives the file the name of the value of
cell Q1 and cell B9 on this sheet. Is this possible?

Thanx a lot in advance...


--

Dave Peterson

  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default

You could convert to values.

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveWorkbook.Worksheets("giro")

wks.Copy 'to a new workbook

With ActiveSheet
With .UsedRange
.Value = .Value
End With
.Parent.SaveAs Filename:="C:\" _
& .Range("q1").Value & .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal
.Parent.Close savechanges:=False
End With

End Sub

You'll have to play catchup with your changes.

I only added:

With .UsedRange
.Value = .Value
End With

Not sure if it's easier to add this change or your print statements.


KingKarl wrote:

Thanx a lot...

This worked fine. I only had to add the line in the macro that tells it to
print :-)

Still, after using this I encoutered another problem: when opening the saved
file and having the original workbook open, the saved file automatically
updated itself with the latest cell values (because alle the cells in "giro"
are linked to another sheet in the workbook). Is there a way to get around
this problem?

Karl Erik Kvalsund

Dave Peterson skrev:

I'm not sure what you have in Q1 and B9, but maybe...

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = ActiveWorkbook.Worksheets("giro")

wks.Copy 'to a new workbook

With ActiveSheet
.Parent.SaveAs Filename:="C:\" _
& .Range("q1").Value & .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal
.Parent.Close savechanges:=False
End With

End Sub

There is no error checking -- make sure those values in Q1 and B9 will make a
nice name.

(Dates are problems. Windows files can't have /'s in them.)

.Parent.SaveAs Filename:="C:\" _
& format(.Range("q1").Value, "yyyy_mm_dd") _
& .Range("b9").Value & ".xls", _
FileFormat:=xlWorkbookNormal

Might work for you.

KingKarl wrote:

I'm struggling with a problem that I bet is easy as ****, but anyway...

I want to make a macro that saves only sheet number five (named "giro") of
my workbook, and at the same time gives the file the name of the value of
cell Q1 and cell B9 on this sheet. Is this possible?

Thanx a lot in advance...


--

Dave Peterson


--

Dave Peterson
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
Saved *.csv file gives SYLK file type warning upon Excel 2003 open Tom Excel Discussion (Misc queries) 5 March 19th 08 03:15 PM
How do you open a template at startup? James Kendall Excel Discussion (Misc queries) 7 July 26th 05 07:33 PM
Automatically update from source when file opens P Flater Excel Discussion (Misc queries) 1 March 25th 05 09:41 PM
Locating a file in excel with a partial file name. Audra Excel Discussion (Misc queries) 2 February 19th 05 08:52 PM
Enter Data Into Another Excel File Automatically Morrisg Excel Worksheet Functions 0 January 11th 05 02:07 AM


All times are GMT +1. The time now is 08:34 AM.

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"