From Excel/VBA open a Word Doc and change opened document style to "normal"

drom

Well-known Member
Joined
Mar 20, 2005
Messages
566
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Hi and Thanks in advance!


I am Opening a Word Doc Using Excel/VBA (No problem)

VBA Code:
Dim wApp As New Word.Application
Dim wDoc As Word.Document

wApp.Visible = True 'False
Application.DisplayAlerts = False
Set wDoc = wApp.Documents.Open(wPageFile, False)
                                                  'wPageFile   =   Is a existing FullName File
Dim docMultiple As Document
Set docMultiple = wApp.Documents(1)
docMultiple.Content.Select                        'Selects the entire  Word Dument (I do not know If this is necessarym If no avoid selecting the entire word doc

Here this does not work:
VBA Code:
                                      docMultiple.Style = ActiveDocument.Styles("Normal")


VBA Code:
'ActiveDocument.FullName = wPageFile


I get this err Code:
VBA Code:
?Err, Err.Description
 438          Object doesn't support this property or method


Thanks!
 
Your macro does not work here. Receiving too many error messages.

The following does work here :

VBA Code:
Option Explicit

Sub OpenWordDocument()
    Dim wdApp As Object
    Dim wdDoc As Object
    Dim filePath As String
    
    ' Set the file path of the Word document to open
    filePath = "C:\Users\logit\OneDrive\Desktop\Untitled 1.docx"
    
    On Error Resume Next
    ' Create a new Word Application object
    Set wdApp = CreateObject("Word.Application")
    On Error GoTo 0
    
    ' Check if Word application was created successfully
    If wdApp Is Nothing Then
        MsgBox "Microsoft Word is not installed or cannot be accessed.", vbCritical
        Exit Sub
    End If
    
    ' Make the Word application visible
    wdApp.Visible = True
    
    ' Open the Word document
    On Error Resume Next
    Set wdDoc = wdApp.Documents.Open(filePath)
    On Error GoTo 0
    
    ' Check if the document was opened successfully
    If wdDoc Is Nothing Then
        MsgBox "The file could not be opened. Please check the file path.", vbCritical
        wdApp.Quit
        Set wdApp = Nothing
        Exit Sub
    End If
    
    MsgBox "Word document opened successfully!"
End Sub
 
Upvote 0
Ok
The Word file is open with any err, but how can I change The entire word document style to "normal" ?


If possible without selecting the word doc​
In my case my FilePath comes with a few different styles like heading1, 2 etc…

Thanks
 
Upvote 0
I can't answer that question for you. Sorry.
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top