OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 15-08-2008, 18:02
burmeisn
Guest
 
Posts: n/a
Default X4 SaveAs Causing Crash

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
Reply With Quote
  #2  
Old 15-08-2008, 18:48
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,769
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default This should work...

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
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 15-08-2008, 19:22
burmeisn
Guest
 
Posts: n/a
Default

That works perfectly! Thanks a ton Shelby, you've saved me a lot of headaches!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -5. The time now is 08:10.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com