As mentioned in the comments, you're mixing late-binding and early-binding, and also need to reference the Word instance.
An early-binding approach might be (add a reference to the Microsoft Word xx.0 Object Library under Tools > References).
Sub MyWord()
Dim wordApp As New Word.Application
Dim myDoc As Word.Document
wordApp.Visible = True
Set myDoc = wordApp.Documents.Add
wordApp.ActiveWindow.View.Type = wdWebView
End Sub
If you want to late-bind, note from the WdViewType
enum docs that wdWebView
corresponds to the value 6.
Sub MyWord()
Const wdWebView As Long = 6
Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add
objWord.ActiveWindow.View.Type = wdWebView
End Sub
wdWebView
has no meaning unless you've referenced the Word type library... in which case late-binding serves little purpose other than making your life much harder than it needs to be. – Mathieu GuindonActiveWindow
is in the scope of the current host application, i.e.Excel.Application.ActiveWindow
- if you want the Word window, you need to work off theobjWord
object. – Mathieu Guindon