| |

VerySource

 Forgot password?
 Register
Search
View: 684|Reply: 1

How to open a word document in a shared folder on another computer, and the other computer has a login password

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-7 13:30:01
| Show all posts |Read mode
How to open a word document in a shared folder on another computer, and the other computer has a login password
Set documents = word.documents.Open ("\\169.254.151.22\E $\test\temp.doc")
If there is no login box, it will report an error.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-19 23:00:01
| Show all posts
Give you a piece of code to create a network connection. After creating a network connection, you can open the server's file through the network path
'************************************************* ************************
'**Number of letters Name: ConnectNetDir
'**Input: szPath(String)-path name
'**: szUser(String)-path access user name
'**: szPwd(String)-path access password
'** Output: return 1 when connected, and return 0 when not connected
'**Function description: Connect to the network path, return 0 if it fails to connect within 10 seconds
'************************************************* ************************
Function ConnectNetDir(szPath As String, szUser As String, szPwd As String)
    Dim retVal
    Dim loopTime As Integer
   
    Dim nOSName As Long'OS name
    Dim nOSVerMajor As Long'Operating system major version number
    Dim nOSVerMinor As Long'Operating system minor version number
    Dim nOSVerRevision As Long'Operating system revision number
    Dim IsWin98 As Boolean
   
    Dim clsOS As COperateSystem
    Set clsOS = New COperateSystem
   
    clsOS.GetOSVersion nOSName, nOSVerMajor, nOSVerMinor, nOSVerRevision
   
    If nOSVerMajor <5 Then'Major version number>=5, it indicates that it is an operating system above win2000
        IsWin98 = True
    Else
        IsWin98 = False
    End If
   
    Set clsOS = Nothing
   
    'Add a space after the machine domain name in the network path name
    'That is "\\Machine\ShareName"---->"\\Machine\ShareName"
    Dim iPos As Integer
    iPos = InStr(3, szPath, "\")
    szPath = Mid(szPath, 1, iPos-1)&""&Mid(szPath, iPos)
   
    If IsWin98 Then
        retVal = Shell("command.com /c net use "&szPath&" "&_
            szPwd&"/user:"&szUser, vbHide)
    Else
        retVal = Shell("cmd.exe /c net use "&Chr(34)&szPath&Chr(34)&_
            ""&szPwd&"/user:"&szUser, vbHide)
    End If
   
    If retVal = 0 Then
        ConnectNetDir = 0
        Exit Function
    End If
   
    On Error Resume Next
   
    loopTime = 0
   
    Do While loopTime <10
        'Detect whether the network path can be accessed
        If Dir(szPath&"\", vbDirectory) = "" Then
            loopTime = loopTime + 1
            Sleep 1000
        Else
            ConnectNetDir = 1
            Exit Function
        End If
    Loop
   
    ConnectNetDir = 0
End Function
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list