![]() |
#1
|
|||
|
|||
![]()
My company is upgrading from CorelDraw11 to X4. I have a macro to save files to a certain folder and I want a yes/no option to overwrite existing files.
I am very new to VBA. I learned it on my own a month ago to speed up our work in CorelDraw 11, so my code is probably abstract, but it did what I wanted it to do in version 11 just fine, however it causes X4 to crash. Any help is greatly appreciated. Code:
Sub Ctrl_F9() On Error GoTo ErrorHandler: Dim Response2 As Integer Response = InputBox("Enter File Name to Save to EngravingCDR") If Response = "" Then Exit Sub Dim opt As New StructSaveAsOptions opt.Filter = cdrCDR opt.Overwrite = False opt.Range = cdrAllPages ActiveDocument.SaveAs "O:\Oentry\Engravingcdr\" & Response & ".cdr", opt ErrorHandler: If Err.Number = -2147467259 Then Response2 = MsgBox("Overwrite Existing File?", vbYesNo) If Response2 = vbYes Then Dim Opt2 As New StructSaveAsOptions Opt2.Filter = cdrCDR Opt2.Overwrite = True Opt2.Range = cdrAllPages ActiveDocument.SaveAs "O:\Oentry\Engravingcdr\" & Response & ".cdr", Opt2 Else Exit Sub End If End If Exit Sub End Sub |
#2
|
||||
|
||||
![]()
It is better to test if the file exists then to try and rely on an error catch. Try this....it should work for you on X4
Code:
Sub Ctrl_F9() Dim Response As String Dim Response2 As VbMsgBoxResult Dim opt As New StructSaveAsOptions Response = InputBox("Enter File Name to Save to EngravingCDR", "SaveAs") If Response = "" Then Exit Sub If Dir("O:\Oentry\Engravingcdr\" & Response & ".cdr") <> "" Then 'Test to see if the file exists Response2 = MsgBox("Overwrite Existing File?", vbYesNo, "SaveAs") If Response2 = vbNo Then Exit Sub End If opt.Filter = cdrCDR opt.Overwrite = True opt.Range = cdrAllPages ActiveDocument.SaveAs "O:\Oentry\Engravingcdr\" & Response & ".cdr", opt End Sub -Shelby |
#3
|
|||
|
|||
![]()
That works perfectly! Thanks a ton Shelby, you've saved me a lot of headaches!
|
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
VB6 crash when using PrintSettings in CD13 | StevenDavison | CorelDRAW/Corel DESIGNER VBA | 10 | 13-01-2008 08:56 |
saveas problems.. | silviopr | CorelDRAW/Corel DESIGNER VBA | 2 | 29-01-2007 10:08 |
Imort Tif- X3 Crash | gperzel | General | 5 | 19-07-2006 09:44 |
crash when exporting .eps's | bloodgroove | General | 3 | 08-02-2006 15:25 |
crash | lizrathke | General | 1 | 18-05-2005 19:59 |