Solved

Vb.net and Word save

Posted on 2012-03-13
12
433 Views
Last Modified: 2012-03-29
Hi,

My visual basic application fills bookmarks in a word document, I'd like to be able to open the savefiledialog in word from vb.net.

I know I can do this by adding : appWord.ActiveDocument.Save()
but I was wondering if it would be possible to define the current path that the savefiledialog starts in (the root), I already know where to save the files but I want to give the user the option to save over the file in the directory or change the name to something else.

Is this at all possible?
0
Comment
Question by:FCapo
  • 6
  • 4
  • 2
12 Comments
 
LVL 14

Expert Comment

by:systan
ID: 37716286
pathfilename = "c:\ilikethisfolder\ilikethisfoldertoo\ilikethisfile.docx"
You can use Word.ActiveDocument.SaveAs2(PathFilename)
0
 

Author Comment

by:FCapo
ID: 37716409
The problem is it doesn't show the dialog, it saves the document in the directory but it doesn't give the user the option to rename it or change location?
0
 
LVL 14

Expert Comment

by:systan
ID: 37716606
you could use:
Word.FileDialog(MsoFileDialogType.msoFileDialogSaveAs)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:FCapo
ID: 37716659
How do I implement this,

If I just paste the code it says : Property access must assign to the property or use its value
0
 
LVL 14

Expert Comment

by:systan
ID: 37716682
Try
Dim fd as Word.Dialog = Word.FileDialog(MsoFileDialogType.msoFileDialogSaveAs)
fd.show()
fd.something...
0
 

Author Comment

by:FCapo
ID: 37716719
I'm getting an odd error message

Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Word.Dialog'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000209B8-0000-0000-C000-000000000046}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
0
 
LVL 14

Expert Comment

by:systan
ID: 37716838
is your activation wizard showing? i meant a not registered version?
0
 
LVL 14

Expert Comment

by:systan
ID: 37716855
You could also use when word application quits:  <wdPromptToSaveChanges>

      Dim missing As Object = System.Reflection.Missing.Value
       Word.Quit(Word.WdSaveOptions.wdPromptToSaveChanges, missing, missing)

OR
you really like not using .Quit?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37717718
One option would be to use the .NET File Save dialog as you can customize it and once the user selects the location and gives a file name, use that with Word.ActiveDocument.SaveAs method.
0
 
LVL 14

Expert Comment

by:systan
ID: 37717869
yes, right, you could use the savefilediaglog
       
Dim sfd As New SaveFileDialog
 sfd.ShowDialog()
WordApp.ActiveDocument.SaveAs2(sfd.FileName)
Great idea CodeCruiser ;-)
0
 

Author Comment

by:FCapo
ID: 37725274
That's a good idea thank you,

If on the other hand I know the path to save the file and I use the following code, it sometimes gives me errors that the pathname is wrong, sometimes it works and sometimes it doesn't (sometimes it saves in the directory and most times it gives me a directory error). Why does it work randomly like this?

Dim s As String =  "S:\OUV. DOSSIER- SOUMISSION\test.doc

appWord.ActiveDocument.SaveAs(s)
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 37726164
It looks like a network drive so network issues may sometimes prevent word from saving.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question