Solved

Rename Word document template without saving in VB.NET visual studio 2008

Posted on 2014-03-07
1
674 Views
Last Modified: 2014-03-07
I have the following VB.NET code that creates a Word document by opening a template and populating it with some of the fields from the windows form created in Visual Studio 2008.

The problem is that everytime it opens the document and populates it with the data, the Word document is named "Document1" and if there are already multiple documents open of the same template then it'll name it "Document2", "Document3" and so on.

Is there a way to have it named to "Quote Form - QuoteNumber", where the QuoteNumber is taken from the Windows Form WITHOUT saving the document because the end user has to decide where to save it I can not hard code where to save it.

Basically, rename the Word document something we want instead of the default Doc1, Doc2 etc.

Hope this is possible. Thank you in advance!

Private Sub ExportWord()

        Dim oWord As Word.Application = CreateObject("Word.Application")
        Dim oDoc As Word.Document = oWord.Documents.Add("\\myserver\my documents\Shared Interdepartmental Folders\Applications\Quote Form.dotx")
oWord.Visible = True
        
oDoc.Bookmarks.Item("QuoteNumber").Range.Text = txtMasterItemNo.Text & "-" & txtQuoteNumber.Text
        oDoc.Bookmarks.Item("QuoteDate").Range.Text = txtQuoteDate.Text
        oDoc.Bookmarks.Item("ExpirationDate").Range.Text = txtExpirationDate.Text

        oWord = Nothing
        oDoc = Nothing

Open in new window

0
Comment
Question by:printmedia
1 Comment
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 39914196
To rename a document, you need to save it to disk:

oDoc.SaveAs("Test.docx")
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now