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

Hi all

When I run this macro it opens the workbook I've just saved, how can I stop
it from opening after the macro has ran.

Sub SaveOneSheet()
Dim Sht As Worksheet
Const PATH As String = "C:\test\"
Set Sht = ActiveWorkbook.Sheets("Test1")
Sht.Select
Sht.Copy
ActiveWorkbook.SaveAs Filename:= _
PATH & Sht.Range("G1") & ".xls", FileFormat:=xlNormal
End Sub

Thanks in advance

Dave


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 373
Default Stop a workbook from Opening

Dave, if you're saying that you only want to save the file once as a
certain name (depending on the value of G1), then you could check to
see whether a file by that name already exists using this function
(from Walkenbach):

Function FileExists(fname) as Boolean
FileExists=Dir(fname)<""
End Function

Sub SaveOneSheet()
Dim Sht As Worksheet
Dim daFile as string
Const PATH As String = "C:\test\"
daFile=PATH & activeworkbook.sheets("Test1").range("G1").value
If Not FileExists(daFile) then
Set Sht = ActiveWorkbook.Sheets("Test1")
? ? Sht.Select
? ? Sht.Copy
? ? ActiveWorkbook.SaveAs Filename:= _
? ? ? ? PATH & Sht.Range("G1") & ".xls", FileFormat:=xlNormal
End If
End Sub

I haven't tested this, but it should work. Of course, if G1's value
changes, then the sheet WILL be saved under the new name.
HTH, James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Stop a workbook from Opening

Thanks Zone, All the best


"Zone" wrote in message
ps.com...
Dave, if you're saying that you only want to save the file once as a
certain name (depending on the value of G1), then you could check to
see whether a file by that name already exists using this function
(from Walkenbach):

Function FileExists(fname) as Boolean
FileExists=Dir(fname)<""
End Function

Sub SaveOneSheet()
Dim Sht As Worksheet
Dim daFile as string
Const PATH As String = "C:\test\"
daFile=PATH & activeworkbook.sheets("Test1").range("G1").value
If Not FileExists(daFile) then
Set Sht = ActiveWorkbook.Sheets("Test1")
? ? Sht.Select
? ? Sht.Copy
? ? ActiveWorkbook.SaveAs Filename:= _
? ? ? ? PATH & Sht.Range("G1") & ".xls", FileFormat:=xlNormal
End If
End Sub

I haven't tested this, but it should work. Of course, if G1's value
changes, then the sheet WILL be saved under the new name.
HTH, James



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
Stop Book1 Opening Dobermann Setting up and Configuration of Excel 0 September 2nd 10 10:50 AM
How do I stop blank workbook from opening when opening an existing kjg Excel Discussion (Misc queries) 3 February 12th 10 09:36 PM
stop opening a blank workbook at start up km Excel Discussion (Misc queries) 1 January 18th 06 07:36 PM
How to make the opening of a workbook conditional upon the opening of another workbook Marcello do Guzman Excel Programming 1 December 16th 03 06:09 AM
How to make opening of workbook conditional of opening of another workbook turk5555[_2_] Excel Programming 2 December 15th 03 11:07 PM


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