?
Solved

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

Posted on 2014-03-07
1
Medium Priority
?
714 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

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

oDoc.SaveAs("Test.docx")
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

765 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