I guess I should look into catering for both situations being the case -- A document already open, and when it is active and a document is opened. I have not had a problem either way.
The only other things I tried to do on initialize were as follows. I don't have 365 to test this. I only have 2010. Maybe the other part of the code sets it up to fail. It anyone with 365 can try the code it would be helpful.
Also a way to bypass the problem code with some sort of popup would be good enough.
Thanks for replying.
p.s the document would more than likely be an .rtf file. Again though I have not encountered an issue.
'Essential to have this selection
selection.Document.Activate
'ActiveDocument.ActiveWindow.View.Type = wdPrintView
With ActiveDocument.Background.Fill
.ForeColor.ObjectThemeColor = wdThemeColorAccent1
.Visible = True
.ForeColor.TintAndShade = 0.8
.Solid
End With
'Select default black and white style for document
ActiveDocument.ApplyQuickStyleSet2 ("Default (Black and White)")
I added to the code. So more graceful exit if no document present.
Private Sub UserForm_Initialize()
If Application.Documents.Count = 0 Then
MsgBox ("No document open 1")
End
End If
End Sub
Sub OpenForm2()
If Application.Documents.Count = 0 Then
MsgBox ("No document open 3")
End
End If
theWordMacros2.Show
End Sub