Consulting

Results 1 to 5 of 5

Thread: Opening a Word document from VBA shows Microsoft Sign In page

  1. #1
    VBAX Newbie
    Joined
    Feb 2013
    Posts
    3
    Location

    Opening a Word document from VBA shows Microsoft Sign In page

    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/Crea...utionId=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)


    Last edited by markinca; 10-09-2018 at 12:21 PM.

  2. #2
    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)
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Feb 2013
    Posts
    3
    Location
    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.

  4. #4
    The download link in your linked page is a link to a zip file - http://www.3gpp.org/ftp/TSG_RAN/WG2_...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.
    Graham Mayor - MS MVP (Word)
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Newbie
    Joined
    Feb 2013
    Posts
    3
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •