#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


So far so good, I just have one more (probably many more) conundrum to
solve.
The code below, supplied via this site, works perfectly. But I have to
make allowance for users requesting via command button the creation of
a new book twice in one day. Conflicting file name. By default I get
the windows File already exists prompt. How can I control this so that
i can direct the navigation if 'No' is selected.

Thanks again



Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

ActiveWorkbook.SaveAs "G:\" & sStr

ActiveWorkbook.Close
Application.ScreenUpdating = False

End Sub


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=384216

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Backup your workbook before trying this macro.



Try this macro, this will prompt whether you want to overwrite , I yes
will overwrite, else it will close workbook without overwriting

Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Book1.xls")
Set ws = Worksheets("Sheet1")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

If file_exist("g:\" & sStr & ".xls") Then
MsgBox "Do you want to overwrite the file", vbYesNo
If vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "g:\" & sStr
Application.DisplayAlerts = True
End If
Else
ActiveWorkbook.SaveAs "g:\" & sStr
End If
ActiveWorkbook.Close
Application.ScreenUpdating = False
End Sub

Function file_exist(str As String)
If Len(Dir(str)) 0 Then
file_exist = True
Else
file_exist = False
End If
End Function


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=384216

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Message Box

Hi Kristan,

You already have a response, but a question: if an archive copy of the file
alredy exists, do you want always to disallow second (or subsequent) saves?

Incidentally, in your copied code (and in Anil's response), you should
reverse the logic of the Application.ScreenUpdating statements. This should
be set to False at the start and True at the end.


---
Regards,
Norman



"Kstalker" wrote in
message ...

So far so good, I just have one more (probably many more) conundrum to
solve.
The code below, supplied via this site, works perfectly. But I have to
make allowance for users requesting via command button the creation of
a new book twice in one day. Conflicting file name. By default I get
the windows File already exists prompt. How can I control this so that
i can direct the navigation if 'No' is selected.

Thanks again



Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

ActiveWorkbook.SaveAs "G:\" & sStr

ActiveWorkbook.Close
Application.ScreenUpdating = False

End Sub


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile:
http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=384216



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Thanks for that. As predicted I have hit another wall

I am trying to run another sub dependent on Yes/No, but regardless o
selection it runs.

How can I prevent this?


Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy


If file_exist("G:\") Then
MsgBox "This file already Exists. Do you want to overwrite it?"
vbYesNo
If vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "G:\\" & sStr
ActiveWorkbook.Close

COMPILE_DATA.COPYUSEDRANG

Application.DisplayAlerts = True
End If

Else

ActiveWorkbook.SaveAs "G:\ & sStr
Worksheets("navigation").Select
End If

Application.ScreenUpdating = False

End Sub

Thanks agai

--
Kstalke
-----------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...fo&userid=2469
View this thread: http://www.excelforum.com/showthread.php?threadid=38421

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


try this macro

it should be If file_exist("G:\" & sStr & ".xls") Then instead of
If file_exist("G:\" ) Then




Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy


If file_exist("G:\" & sStr & ".xls") Then
MsgBox "This file already Exists. Do you want to overwrite it?"
vbYesNo
If vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "G:\\" & sStr
ActiveWorkbook.Close

compile_data.CopyUsedRange

Application.DisplayAlerts = True
End If

Else

ActiveWorkbook.SaveAs "G:\ & sStr
Worksheets("navigation").Select
End If

Application.ScreenUpdating = False

End Su

--
anilsolipura
-----------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...fo&userid=1627
View this thread: http://www.excelforum.com/showthread.php?threadid=38421



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Hi Norman.

Cheers for the input, will reverse the application.Statusupdating.

The saved file is date stamped in file name and the user should ideall
be only archiving weekly. So I am really trying to give them as man
chances as possible to think about overwritting existing archive fo
that day.



Regards

Krista

--
Kstalke
-----------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...fo&userid=2469
View this thread: http://www.excelforum.com/showthread.php?threadid=38421

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Message Box

Hi Anil,

MsgBox "This file already Exists. Do you want to overwrite it?",
vbYesNo
If vbYes Then


Using this code, Kristan's file will be overwritten both if the user agrees
or disagrees. I think that you could rewrite this as:

Dim Res as long

Res = MsgBox("This file already Exists. " & _
"Do you want to overwrite it?", vbYesNo)
If Res = vbYes Then

---
Regards,
Norman



"anilsolipuram"
wrote in message
news:anilsolipuram.1rmn2c_1120449902.3561@excelfor um-nospam.com...

try this macro

it should be If file_exist("G:\" & sStr & ".xls") Then instead of
If file_exist("G:\" ) Then




Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy


If file_exist("G:\" & sStr & ".xls") Then
MsgBox "This file already Exists. Do you want to overwrite it?",
vbYesNo
If vbYes Then
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "G:\\" & sStr
ActiveWorkbook.Close

compile_data.CopyUsedRange

Application.DisplayAlerts = True
End If

Else

ActiveWorkbook.SaveAs "G:\ & sStr
Worksheets("navigation").Select
End If

Application.ScreenUpdating = False

End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile:
http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=384216



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default Message Box

a simple reply:

Option Explicit
Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim newWB As Workbook
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = ThisWorkbook ' Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = "G:\" & Format(Date, "yymmdd") & " " & "Stage Clearer"
ws.Copy

If Dir(sStr) = "" Then
ActiveWorkbook.SaveAs "G:\" & sStr
Else
sStr = Application.GetSaveAsFilename()
If UCase(sStr) < "false" Then
ActiveWorkbook.SaveAs sStr
End If

End If
ActiveWorkbook.Close
Application.ScreenUpdating = False

End Sub


"Kstalker" wrote:


So far so good, I just have one more (probably many more) conundrum to
solve.
The code below, supplied via this site, works perfectly. But I have to
make allowance for users requesting via command button the creation of
a new book twice in one day. Conflicting file name. By default I get
the windows File already exists prompt. How can I control this so that
i can direct the navigation if 'No' is selected.

Thanks again



Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String

Application.ScreenUpdating = True

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

ActiveWorkbook.SaveAs "G:\" & sStr

ActiveWorkbook.Close
Application.ScreenUpdating = False

End Sub


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=384216


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Thanks Anil, Norman and Patrick.

I am now unfortunately greeted with a runtime error for the 'ws.copy'

Further help would be greatly appreciated.


Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String
Dim Res As Long

Application.ScreenUpdating = False

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

If file_exist("G:" & sStr & ".xls")") Then

Res = MsgBox("This file already Exists. " & _
"Do you want to overwrite it?", vbYesNo)
If Res = vbYes Then


Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "G:\" & sStr
ActiveWorkbook.Close

compile_data.CopyUsedRange

Application.DisplayAlerts = True
End If

Else


ActiveWorkbook.SaveAs "G:\" & sStr
Worksheets("navigation").Select
End If

Application.ScreenUpdating = True

End Sub

Function file_exist(str As String)
If Len(Dir(str)) 0 Then
file_exist = True
Else
file_exist = False
End If
End Function


Thanks Again


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=384216

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Problem solved. SP1 was not installed on the terminal.

Code works a treat with one niggle left. I am left with a workbook open
and untitled when the user does not want to overwrite the file.

How can I remove this?

Again, thanks.


--
Kstalker
------------------------------------------------------------------------
Kstalker's Profile: http://www.excelforum.com/member.php...o&userid=24699
View this thread: http://www.excelforum.com/showthread...hreadid=384216



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Message Box


Backup the workbook before trying this macro.

I am assuming that you just want to close the file, if user doesnot
want to overwrite.

Sub CreateArchive()

Dim Wb As Workbook
Dim ws As Worksheet
Dim sStr As String
Dim Res As Long

Application.ScreenUpdating = False

Set Wb = Workbooks("Single Sheet.xls")
Set ws = Worksheets("Master")
sStr = Format(Date, "yymmdd") & " " & "Stage Clearer"

ws.Copy

If file_exist("G:" & sStr & ".xls")") Then

Res = MsgBox("This file already Exists. " & _
"Do you want to overwrite it?", vbYesNo)
If Res = vbYes Then


Application.DisplayAlerts = False
ActiveWorkbook.SaveAs "G:\" & sStr
ActiveWorkbook.Close

compile_data.CopyUsedRange

Application.DisplayAlerts = True
Else
Application.DisplayAlerts = False
ActiveWorkbook.Close

Application.DisplayAlerts = true

end if


Else


ActiveWorkbook.SaveAs "G:\" & sStr
Worksheets("navigation").Select
End If

Application.ScreenUpdating = True

End Sub


--
anilsolipuram
------------------------------------------------------------------------
anilsolipuram's Profile: http://www.excelforum.com/member.php...o&userid=16271
View this thread: http://www.excelforum.com/showthread...hreadid=384216

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
message box Hein Excel Discussion (Misc queries) 2 October 21st 08 07:10 AM
Message Box Wayne Excel Discussion (Misc queries) 2 April 9th 07 12:10 PM
changing the message in an error message The Villages DA Excel Worksheet Functions 2 February 18th 05 05:30 PM
message box Myriam Excel Programming 4 November 29th 04 11:49 PM
Displaying a message in a message box without requiring user to click anything to proceed Android[_2_] Excel Programming 2 June 25th 04 06:44 PM


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