Log in

View Full Version : Opening a Word document from VBA shows Microsoft Sign In page



markinca
10-09-2018, 12:08 PM
When I open certain Word documents in Word (or Excel) VBA, the Microsoft sign in page shows up (see below). However, if I just double click on the file from Windows Explorer, the file opens just fine without showing this sign in page. Also, if I manually exit the popup window the document loads without any issue. This only happens on certain documents but the sign in page halts the macro.

Any ideas as to why this is happening and how to stop it?

I have tried almost everything listed on forums. Deleting credentials, logged into Office, etc.


Thanks,

Mark

Document Download Link from Source: https://portal.3gpp.org/ngppapp/CreateTdoc.aspx?mode=view&contributionId=867945


Code Segment:



Dim wdApp As Word.Application

Set wdApp = New Word.Application
wdApp.Visible = True

Dim wd As Word.document
Set wd = wdApp.Documents.Open(doc)

https://social.msdn.microsoft.com/Forums/getfile/1336417

gmayor
10-14-2018, 05:00 AM
Looking at your illustration and code, it seems that you are running the code from another VBA enabled application, and that doesn't recognize the format of the document reported as "RAN2_101bis_Sanya." (which is not a Word document name) and so it asks you to help it out. For the code to work you should supply the full name and path of the file - including its extension - so that the application knows what to do with it. I also suggest using variable names that VBA is unlikely to confuse.


Dim wdApp As Object
Dim wd As Object
Dim strDoc As String
strDoc = "C:\Path\doc1.docx" 'the full path of the document
On Error Resume Next
Set wdApp = GetObject(, "Word.Application") 'Get Word if it is running
If Err Then
Set wdApp = CreateObject("Word.Application") 'If not start Word
End If
On Error GoTo 0
wdApp.Visible = True
Set wd = wdApp.Documents.Open(strDoc)

markinca
10-14-2018, 04:26 PM
Thanks for the reply but I AM supplying the full file name and I am NOT supplying the name "RAN2_101bis_Sanya." The code posted is only a small section of the code that does the opening of the file. If you download the file from the link above and try to open it in VBA, you will see exactly what I am talking about. Here is a subroutine that you can use to replicate exactly what I am talking about for yourself:



Sub Test()

Dim doc As String
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Add "Doc Files", "*.docx; *.doc", 1
.Show

If .SelectedItems.Count = 1 Then
doc = .SelectedItems.Item(1)
Else
End
End If
End With


Dim wdApp As Word.Application

Set wdApp = Nothing
Set wdApp = Application ' New Word.Application
wdApp.Visible = True

Dim wd As Word.Document

Set wd = wdApp.Documents.Open(doc)

End Sub




BTW, it is only this file and files like this one that have an issue. Other files open fine. This file uses sharepoint security in some way but what is odd is that the file opens fine using Windows Explorer double click.

gmayor
10-14-2018, 08:50 PM
The download link in your linked page is a link to a zip file - http://www.3gpp.org/ftp/TSG_RAN/WG2_RL2/TSGR2_101/Docs/R2-1802772.zip ?
Word will not open zip files. However if the file is extracted, you do indeed get the log-in screen you referred to. If you escape from that screen without entering a value the document opens. So far I have not found a way to escape from that screen in code.

markinca
10-15-2018, 07:16 AM
Yes that is the problem. However, if you open the file via windows explorer, the popup does not show up so it is something that is unique about VBA.

markinca
11-06-2018, 03:01 PM
The download link in your linked page is a link to a zip file -
Word will not open zip files. However if the file is extracted, you do indeed get the log-in screen you referred to. If you escape from that screen without entering a value the document opens. So far I have not found a way to escape from that screen in code.So I have discovered what is causing the issue. The document uses a template that is located on a SharePoint server but the template does not have public access. So for some reason opening the file in VBA is an issue but when opening the file in windows, there is no issue.

Does anyone have any ideas?

Thanks