#1
|
|||
|
|||
How to suppress saveas dialog from VB6
I have an application written in VB6. Once I have created a word document within the application and do a saveas the save as dialog pop ups and my application waits for the user to click on "Save".
I have set the filename and file format before calling saveas. Since this application is supposed to run unattended as an application this is a problem. This worked with Office 2003 but when we upgraded to Office 2010 we now have the application waiting for a user to click "Save" Any ideas on what setting I need to change so that the Save dialog is suppressed and the file is just saved based on the filename and type set in the VB6 application? Thanks. |
#2
|
||||
|
||||
Is there a reason you're working through the SaveAs dialogue, rather than using .SaveAs?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
Apparently Office 2003 was willing to open a document that was rtf internally and then save it back to the same name but using the Office 2003 Word doc format without asking for confirmation from the user. This was how the application was able to provide different internal formats for .doc files. I think Microsoft has changed the rules again and I am just out of luck. Does anyone have any ideas. |
#4
|
||||
|
||||
That's all very well, but it still doesn't explain why you're trying to work through the dialogues instead of using the .SaveAs method - using the dialogues has never been necessary and using the .SaveAs method avoids any prompts. Done properly, even using the dialogues should be completely transparent. As you haven't posted any code, though, I can't comment on what its issues might be.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
I am using the SaveAs method and I am setting the format but Word still prompts me as the file that I have open is rtf. If I have opened a file whose internal format is Word doc then Word doesn't display the Save dialog. Here's some code
Code:
Private Sub Form_Load() On Error GoTo testerr Dim WW As Object Dim FileName As String Dim SaveFormat As Long FileName = "C:\tmp\test.doc" SaveFormat = 0 Set WW = CreateObject("Word.Application") WW.Visible = True WW.Documents.Open FileName WW.activedocument.SaveAs FileFormat:=SaveFormat WW.activedocument.Close Exit Sub testerr: MsgBox ("error occurred " & Err.Description) End Sub Word still allows you to do that but you will have to rename the file to test.doc. Create a VB6 project with just a form and run it. Save dialog will come up every time and I have no idea how to tell Word that I really want to save this file as a file with doc or docx internal format. Too bad Word keeps getting modified so that it is "better". If you create a file that is really a doc file and run the code then Save dialog does not come up. I'm open to any thoughts on how I can do this from a MS MVP Word expert. Currently probably going to have go with a kludge like ClickOff. Thanks Last edited by macropod; 05-07-2014 at 06:54 PM. Reason: Added code tags |
#6
|
||||
|
||||
The prompt is most likely due to the fact that the document was originally opened in one format and is being saved in another but you're not releasing the version in its original format. I would expect Word to behave this way in all versions. All you need do is change:
WW.ActiveDocument.Close to: WW.ActiveDocument.Close False PS: I also note that, although you have: FileName = "C:\tmp\test.doc you don't use it in: WW.activedocument.SaveAs FileFormat:=SaveFormat
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Quote:
But like any good newby I tried it which you obviously didn't and it didn't help which was not much of a surprise. I really appreciate your time and effort in looking at my problem. |
#8
|
||||
|
||||
Did you try it?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
That's what I said in my previous post.
I tried it but you obviously didn't try your solution or you would have found out that it doesn't work for the reasons that I also put in my previous post. |
#10
|
||||
|
||||
It works for me...
Although it shouldn't be necessary, you might try changing: WW.activedocument.SaveAs FileFormat:=SaveFormat to: WW.activedocument.SaveAs2 FileFormat:=SaveFormat
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
Can you send me the file that you test that is rich text format so I verify that it's not something that I am doing wrong when creating my rtf file?
Thanks |
#12
|
||||
|
||||
See attached. As I don't have VB6, I'm running the code as an ordinary macro from within the document itself. I've modified the code to save the file to the desktop. The macro is in the 'ThisDocument' module.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Quote:
It appears that you are confused about internal formats and the suffix that a file has. A file with a suffix of rtf does not mean that the internal contents are rtf. |
#14
|
||||
|
||||
I created the file in Word 2010 and used SaveAs to save it as an RTF file. I didn't then go an examine the contents, as I expected the output to conform to the RTF specifications. I am not confused as to formats vs file extensions. I suppose I should have twigged to something being amiss when it allowed me to save the file with the macro. Attached is another file - this time a true RTF. The macro that's in the other one works fine with this file too.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
Quote:
Apparently it isn't Try this code snippet using cscript and then we will be comparing apples to apples. I have used both Windows 7 (32 bit) , Windows 2008 R2, and XP to demonstrate that the Save dialog always comes up with Word 2010 or Word 1013. I realize this is not strictly a Word question but it does have to do with the Word object. Dim WW Dim FileName Dim SaveFormat FileName = "C:\tmp\sample.rtf" SaveFormat = 0 Set WW = CreateObject("Word.Application") WW.Visible = True WW.Documents.Open FileName call WW.activedocument.SaveAs (FileName, SaveFormat) WW.activedocument.Close False where c:\tmp\sample.rtf is internally an rtf file. The last sample.rtf file you sent me was internally an rtf file. Thanks again. |
Tags |
save as, suppress |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Disabling Word's Save and SaveAs commands | Catty | Word VBA | 6 | 03-19-2014 03:21 AM |
Saveas error handling | jillapass | Word VBA | 7 | 03-30-2012 03:24 PM |
saveAs ChDir _ | tinfanide | Excel Programming | 4 | 11-05-2011 01:40 AM |
Suppress Dialog Box | crutch024 | Word | 0 | 08-17-2010 09:52 AM |
Suppress "do you want to save?" dialog on close | rnstewart | Excel | 2 | 12-28-2005 04:30 PM |