Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-03-07
1
Medium Priority
?
727 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 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