[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 738
  • Last Modified:

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

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
printmedia
Asked:
printmedia
1 Solution
 
Jacques Bourgeois (James Burger)Commented:
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now