I am having a problem in X5 where I am attempting to save a file using the ActiveDocument.SaveAs command:Even though I have set all available properties and supplied a full file path to save the file, I am still being shown a confirmation save as dialog window. I'd like this save operation (and a corresponding print operation) to occur silently without any user intervention, but the API documentation does not seem to address this. I understand this behavior did not happen in earlier releases (at least that is what I've read on other forums) so I'm wondering if anyone has noticed this odd behavior in X5 as well and has a workaround / undocumented solution?Relevant code sample below:
' These assignments and their corresponding declarations occur in another module (they're global in scope) AppPath = "C:\Wizard" ' Directory containing Wizard support files CDRPath = "CDR" ' Directory to archive saved Corel Draw Files TicketPath = "Tickets" ' Directory to archive saved Claims Tickets '...After assigning these variables, I test and confirm that I DO have a value stored for the full path in the concatenated location I'm using below...Public Sub CreateSign(ByVal SignNumber As Integer, ByVal Name As String, ByVal ID As String, ByVal NameWidth As Double, ByVal NameHeight As Double, ByVal NameLeftPos As Double, ByVal NameBottomPos As Double, Optional ByVal Save As Boolean)On Error GoTo ERR_CreateSign Dim sh As Shape Dim doc As Document Dim FileName As String ' Select Text Name Shape If SignNumber = 1 Then ActivePage.Shapes.FindShape(Query:="@name = 'Name1'").CreateSelection ElseIf SignNumber = 2 Then ActivePage.Shapes.FindShape(Query:="@name = 'Name2'").CreateSelection End If Set sh = ActiveShape ' Set my Shape Object to the currently selected active shape ' Update it's text contents sh.Text.Story = Name ActiveDocument.Unit = cdrInch ActiveDocument.ReferencePoint = cdrBottomLeft ' Resize to NameWidth x NameHeight sh.SizeWidth = NameWidth sh.SizeHeight = NameHeight ' Left - Align Text Field to NameLeftMargin sh.LeftX = NameLeftPos sh.BottomY = NameBottomPos ' Deselect the current shape ' Select the Text ID Shape If SignNumber = 1 Then ActivePage.Shapes.FindShape(Query:="@name = 'SignID1'").CreateSelection ElseIf SignNumber = 2 Then ActivePage.Shapes.FindShape(Query:="@name = 'SignID2'").CreateSelection End If ' Set my Shape Object to the currently selected active shape Set sh = ActiveShape ' Update it's text contents sh.Text.Story = ID ' If we've been asked to Save this document on this call If (Save) Then Dim opt As New StructSaveAsOptions ' Create a unique file name with Time/Date Stamp and .CDR Extension FileName = AppPath & "\" & CDRPath & "\" & Format(Now, "d-mmm-yyyy-hh-mm-ss") & ".cdr" ' Set Options opt.EmbedICCProfile = True opt.EmbedVBAProject = False opt.Filter = cdrCDR opt.IncludeCMXData = True opt.Overwrite = True opt.Range = cdrAllPages opt.Version = cdrCurrentVersion ' Save File ActiveDocument.SaveAs FileName, opt End If Exit_CreateSign: Exit SubERR_CreateSign: MsgBox Err.Description Resume Exit_CreateSignEnd Sub
Could be an issue with the user privileges -> On Win VISTA and WIn7 the User Account Control may not give you access to your C: drive.
Solution 1: Save the files to the User or Public folders.
Sub Test() Dim d As Document Set d = CreateDocument d.ActiveLayer.CreateRectangle 1, 2, 3, 4 d.SaveAs UserWorkspacePath & "Filename.cdr"End Sub
Solution 2: Disable Windows' User Account Control (this setting is for security purposes and is not recommended)
Kieran,
Thank you for your advice. I actually had tried this earlier and discovered that is exactly the problem. On Vista & Windows 7 (I'm running Win7) the new security restrictions prevent saving directly to disk unless you're in the user's home directory or working in a directory that has had the inherited permissions from the parent disabled (C:\ is naturally locked to all but admin users).
Thanks!