Opening word doc from VBA - vba

I have a subroutine in MS Access that opens a specific word doc file. The gist of the code is
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim filepath as String
'Open Word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
filepath = CurrentProject.Path & "\Prospect Profiles\Account Profile Form.doc"
'Open the file
Set wrdDoc = wrdApp.Documents.Open(filepath)
So here's the kicker - The subroutine works for all but one of our employees. We're all on the same Citrix environment, and we all have the same version of Access and Word. For this user, the subroutine does not give an error - it smiply opens a blank instance of ms word but it never opens the word doc file. What gives?

Aha! It turns out that this user had made a copy of an older version of our database front end and he wasn't accessing our current, updated version. Thanks for all the help y'all!

Related

Run Time Error Generated when opening Microsoft Word Document from Excel VBA

Receiving a Runtime Error '13' exception when creating a word application object. I also was experiencing relatively extreme delays (on the order of 20-30 seconds) of running prior to the exception. Any idea what this could be from? I searched Stackoverflow and I haven't seen anything that was very similar.
I have never worked with an word doc from excel before so this is something new to me.
Code Below:
Public Sub GetRawData()
'Meant to translate data from a raw word file and format into excel
Dim filePath As String
Dim objWord As Application
Set objWord = CreateObject("Word.Application")
Dim objDoc As Word.Document
'File management vars
Dim oneLine As Paragraph
Dim lineText As String
filePath = "U:\Research_Dev Docs\DevFolder\Word Doc Translation In Excel For Phys\testWordDoc.docx"
'Set word doc object using standard file directory and file name
Set objDoc = objWord.Documents.Open(Filename:=filePath, Visible:=True)
For Each oneLine In objDoc.Paragraphs
'Pull in each line and eventually parse
lineText = oneLine.Range.Text
'DEBUG OUTPUT TO THE SCREEN FOR TESTING
MsgBox (lineText)
Next oneLine
End Sub

VB.Net working with ActiveDocument in an already running instance of word

I have a small VB.Net application which opens a new word document from a template (opens as Document1.docx for example). It runs some code to find a replace some text.
It then allows the user to edit the open document. There is a small winform open with a button called 'Complete'. When the user clicks this, I want it to save the document and do some further editing etc.
However, I cannot get the code to work to see the active document in the running instance of Word.
Whenever I refer to the activedocument, it throws and exception saying there are no documents open.
The code which is looking to save the active document is in a separate sub from where the Word.Application object is created. Word is running with the document open but it still fails.
I've tried the following to make sure it is getting the instance of word that is open;
WordApp = Marshal.GetActiveObject("Word.Application")
But is still does not see any open documents.
Any suggestions?
EDIT #1 - Sorry for not including the code;
This is the code that starts Word and does some basic find/replace. It then starts form3 which stays in place whilst the user edits the word document. This code runs from a button click on form 2;
Dim oWord As Word.Application
Dim oDoc As Word.Document
Dim path As String
path = "C:\Templates/"
Try
oWord = CreateObject("Word.Application")
oWord.Visible = True
Catch ex As Exception
''Some error handling code not included for the purpose of StackOverflow
End Try
Try
oDoc = oWord.Documents.Add(path & "MG11.dot")
Catch ex As Exception
''Some error handling code not included for the purpose of StackOverflow
End Try
With oWord.Selection.Find
''Find & Replace Code - this works so is not included for Stackoverflow
End With
Form3.Show()
Me.WindowState = FormWindowState.Minimized
Form1.WindowState = FormWindowState.Minimized '(form 1 has no code which effects Word)
End Sub
Form 3 has one button, which when pressed should save the word document. It will give it a filename based on info from elsewhere. Only the basic code is shown here - I just need to get vb.net to see the active document for now. This code is ran on Button_1 Click for Form 3.
Dim WordApp As Word.Application
Dim oDoc As Word.Document = WordApp.ActiveDocument
oDoc = WordApp.ActiveDocument
I've also tried;
Dim WordApp As Word.Application
WordApp = Marshal.GetActiveObject("Word.Application")
Dim oDoc As Word.Document
oDoc = WordApp.ActiveDocument
'once oDoc is set properly I will use SaveAs2 to handle the saving etc
It fails on WordApp.ActiveDocument, stating there are no open documents.
Either make sure oWord is in scope in your Form3. It might already be in scope or you add a Public Word.Applications property to your Form3 and set that property before showing the form.
In the first case you access the ActiveDocument on the existing oWord object in scope, in the second you set the property on the form and access that before showing.
oWord.ActiveDocument

Word.application.Selection.Find.Text With multiple Word applications open

I'm having a problem where when I use the Word.Application.Selection.Find set of commands, I run into a NullReferenceException. In this program I initialize a new Word document as such:
Dim wrdApp As Word.application = New Word.Application
Dim wrdDoc As Word.Document = New Word.Document
wrdApp.Visible = True
With wrdDoc
wrdApp.Selection.Find.ClearFormatting()
wrdApp.Selection.Find.Text = sequenceObject(i, 1, 1, 1).cat
wrdApp.Selection.Find.Forward = True
wrdApp.Selection.Find.Wrap = Word.WdFindWrap.wdFindContinue
wrdApp.Selection.Find.Execute
End With
When I have no windows open prior to the code running, I have no problem. If I have another word document open at the time, the error occurs at the first Find command; it used to occur at the ClearFormatting line. I commented it out, then it occurred at the Find.Text line. I have the correct object libraries referenced and imported.
I figured it out, I wasn't actually specifying which document to select. By using
wrdApp.ActiveDocument.ActiveWindow
I was able to solve the problem.

Check to see if word document is open before opening

I have a basic macro that opens up a word document, which works just fine. However if the document is already open then a new 'read-only' version is loaded. Is there a way to check if the document is already open, and if so switch to it rather than open a new copy.
Sub Open_Word_Document()
Dim objWord As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open Filename:=ThisWorkbook.Path & "\template.docx"
End Sub
EDIT:
This has been edited to suggest this question is already answered, but as the comments state the suggested question is referring to a different MS Application.

How to programmatically open the Document Information Panel in Microsoft Word 2010

Could anyone show me an example on how to open the document information panel in word with vb.net. If you happen to wonder what document panel I refer to you can check screenshots at:
How to Open the Document Information Panel in Microsoft Word 2010
Here is my code so far:
Dim dialogBox As Word.Dialog = Globals.ThisAddIn.Application.Dialogs(Word.WdWordDialog.wdDialogFileSummaryInfo)
dialogBox.Show()
I've managed to open it up but it seems to be the wrong type of document panel.
try this
Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add
oWord.DisplayDocumentInformationPanel = True