我想打开服务器上的word文档,服务器有用户密码,文件夹也开了共享,如何打开word.我用的是下面的语句,但是一定要网络邻居登陆过服务器才行,不知道在程序例怎么先登陆再访问
Dim word As Object
Dim documents As Object
Private Sub Command1_Click()
Set word = CreateObject("word.application")
Set documents = word.documents.Open("\\169.254.151.22\E$\liling\temp.doc")
word.Visible = True
End Sub
Dim word As Object
Dim documents As Object
Private Sub Command1_Click()
Set word = CreateObject("word.application")
Set documents = word.documents.Open("\\169.254.151.22\E$\liling\temp.doc")
word.Visible = True
End Sub
'*************************************************************************
'**函 数 名:ConnectNetDir
'**输 入:szPath(String) - 路径名
'** :szUser(String) - 路径访问用户名
'** :szPwd(String) - 路径访问密码
'**输 出:连接上返回1,连接不上返回0
'**功能描述:连接网络路径,10秒钟内连接不上则返回0
'*************************************************************************
Function ConnectNetDir(szPath As String, szUser As String, szPwd As String)
Dim retVal
Dim loopTime As Integer
Dim nOSName As Long 'OS 名称
Dim nOSVerMajor As Long '操作系统主版本号
Dim nOSVerMinor As Long '操作系统次版本号
Dim nOSVerRevision As Long '操作系统修正号
Dim IsWin98 As Boolean
Dim clsOS As COperateSystem
Set clsOS = New COperateSystem
clsOS.GetOSVersion nOSName, nOSVerMajor, nOSVerMinor, nOSVerRevision
If nOSVerMajor < 5 Then '主版本号>=5,表明是win2000以上的操作系统
IsWin98 = True
Else
IsWin98 = False
End If
Set clsOS = Nothing
'在网络路径名中的机器域名后加一个空格
'即"\\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
'检测网络路径是否能够访问
If Dir(szPath & "\", vbDirectory) = "" Then
loopTime = loopTime + 1
Sleep 1000
Else
ConnectNetDir = 1
Exit Function
End If
Loop
ConnectNetDir = 0
End Function