vba問題,新手請教高手。。急死人啦

yy830024 2009-10-13 02:26:34
需要打开EXECL 打开 ftp://10.172.1.114上某个TEXT文档 ,先判断该文件是否为空,
如果不为空就打开该文件。
我的判断语句为:
1.path=ftp://10.172.1.114/delete/lbfs01.nbpb.com/Z/LCD/4622/T56BW/T56BW076/T56BW076BD09.txt
aa=dir(path)
运行时出错
2.Set fs = CreateObject("Scripting.FileSystemObject", path)
aa = fs.FileExists(path)
运行是不管文件存在。总是返回 false.
请教高手,为什么会这样?该怎么写啊?
请教高手。最好附上代码,另外还有打开该TEXT的代码啊。。谢谢了

我只有这么多分了。
...全文
161 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
linc_M 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 19 楼 yy830024 的回复:]
引用 18 楼 linc_m 的回复:
为什么要用Excel 读 TXT?? Excel读TXT是要经过转换的!上面的aa是什么?aa=dir(path)???



path表示路径,如果该文件不存在,aa的值为0。
[/Quote]

我知道Path是路径 我的意思是aa是什么??是什么变量? Boolean还是String什么的?不知道在VBA里
你这样写会返回什么,但是vb里这样写返回的是Path的值 而不是返回Fale or True值!而且再重复一次Excel读TXT是要转换的!


Zondi 2009-10-15
  • 打赏
  • 举报
回复
换分中....
yy830024 2009-10-15
  • 打赏
  • 举报
回复
[Quote=引用 21 楼 cbirdno1no1 的回复:]
使用winsock。先登录,再读写文件。
[/Quote]

看来只能这样了。。
of123 2009-10-15
  • 打赏
  • 举报
回复
dir 不支持网络文件。dir 是通过本地文件系统来运作的。
cBirdNO1NO1 2009-10-15
  • 打赏
  • 举报
回复
使用winsock。先登录,再读写文件。
linc_M 2009-10-14
  • 打赏
  • 举报
回复


为什么要用Excel 读 TXT?? Excel读TXT是要经过转换的!上面的aa是什么?aa=dir(path)???
yy830024 2009-10-14
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 linc_m 的回复:]
为什么要用Excel 读 TXT?? Excel读TXT是要经过转换的!上面的aa是什么?aa=dir(path)???

[/Quote]

path表示路径,如果该文件不存在,aa的值为0。
yy830024 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 getemail 的回复:]
Private Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type

ftCreationTime As FILETIME
编译错误:用户定义类型未定义
[/Quote]
getemail 2009-10-13
  • 打赏
  • 举报
回复
getemail 2009-10-13
  • 打赏
  • 举报
回复
Private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, ByVal dwContent As Long) As Long
捧剑者 2009-10-13
  • 打赏
  • 举报
回复
Option Explicit

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _
(ByVal sAgent As String, ByVal LAccessType As Long, ByVal sProxyName As String, _
ByVal SProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _
(ByVal hInternetSession As Long, ByVal sServerName As String, _
ByVal nServerPort As Integer, ByVal sUsername As String, _
ByVal sPassword As String, ByVal lService As Long, _
ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, _
ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, ByVal dwFlags As Long, _
ByVal dwContext As Long) As Boolean

Public Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" _
(ByVal hFtpSession As Long, ByVal lpszFileName As String) As Boolean

Public Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" _
(ByVal hFtpSession As Long, ByVal lpszExsiting As String, ByVal lpszNew As String) As Boolean

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

Public Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" _
(ByVal hFtpSession As Long, ByVal lpszSearchFile As String, _
lpFindFileData As WIN32_FIND_DATA, ByVal dwFlags As Long, _
ByVal dwContent As Long) As Long

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" _
(ByVal hFind As Long, lpvFndData As WIN32_FIND_DATA) As Long

Public Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Public Type WIN32_FIND_DATA
dwFilAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * 260
cAlternate As String * 14
End Type


Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Private Sub Command1_Click()
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, "ip地址", 0, _
"用户名", "密码", 1, 0, 0)
If lnginetconn Then
blnRC = FtpGetFile(lnginetconn, "website/address.asp", "c:\address.asp", 0, 0, 1, 0)
If blnRC Then
MsgBox "download ok!!!"
End If
InternetCloseHandle lnginetconn
InternetCloseHandle lnginet
MsgBox "close ok!!!"
Else
MsgBox "can't connect"
End If
Else
MsgBox "ftp wrong"
End If
End Sub

Private Sub Command2_Click()
Dim pData As WIN32_FIND_DATA
Dim lngHINet As Long
Dim intError As Integer
Dim strTemp As String
Dim blnRC As Boolean
pData.cFileName = String(260, 0)
lnginet = InternetOpen(vbNullString, INTERNET_OPEN_TYPE_PRECONFIG, _
vbNullString, vbNullString, 0&)
If lnginet Then
lnginetconn = InternetConnect(lnginet, "IP地址", 0, _
"用户名", "密码", 1, 0, 0)
If lnginetconn Then
lngHINet = FtpFindFirstFile(lnginetconn, "*.*", pData, 0, 0)
strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
Do
pData.cFileName = String(260, 0)
blnRC = InternetFindNextFile(lngHINet, pData)
If Not blnRC Then
Exit Do
Else
strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1)
End If

Loop
Text1.Text = strTemp
End If
End If
InternetCloseHandle lngHINet

InternetCloseHandle lnginetconn
InternetCloseHandle lnginet


End Sub
getemail 2009-10-13
  • 打赏
  • 举报
回复
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
getemail 2009-10-13
  • 打赏
  • 举报
回复
通用里面加个:

Public Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
yy830024 2009-10-13
  • 打赏
  • 举报
回复
楼上的。能不能说具体点。。。最好有代码 啊。。
看来没有什么好的办法了..
我在网上找到了一段代码,但是仍然编译不过啊。郁闷
WIN32_FIND_DATA无定义之类的
Sub test()

Dim sFile As String
sFile = "ftp://xxxx:123456@10.216.*.*/e:/200804/11/0000.xls"

Dim hFind As Long
Dim hConnection As Long
Dim nLastError As Long
Dim pData As WIN32_FIND_DATA
hFind = FtpFindFirstFile(hConnection, sFile, pData, 0, 0)
nLastError = Err.LastDllError
If hFind = 0 Then
If (nLastError = ERROR_NO_MORE_FILES) Then
Cells(1, 1).Value = -1 ' File not found
Else
Cells(1, 1).Value = -2 ' Other error
End If

End If

InternetCloseHandle (hFind)
捧剑者 2009-10-13
  • 打赏
  • 举报
回复
如果要ftp,可以先用inet下载,再用fso打开。
捧剑者 2009-10-13
  • 打赏
  • 举报
回复
fso好像不支持ftp吧,只能支持网络共享;
//10.172.1.114/delete/lbfs01.nbpb.com/Z/LCD/4622/T56BW/T56BW076/T56BW076BD09.txt
yy830024 2009-10-13
  • 打赏
  • 举报
回复
还是不行。。老马人列》》》、?
捧剑者 2009-10-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yy830024 的回复:]
賬號:nbpb\lcdft
密碼:lcd
高手都到那去啦》???急哦。。
[/Quote]
ftp://lcdft:lcd@10.172.1.114/delete/lbfs01.nbpb.com/Z/LCD/4622/T56BW/T56BW076/T56BW076BD09.txt
试试。
其它的偶不懂。
getemail 2009-10-13
  • 打赏
  • 举报
回复
帮顶
yy830024 2009-10-13
  • 打赏
  • 举报
回复
賬號:nbpb\lcdft
密碼:lcd
高手都到那去啦》???急哦。。
加载更多回复(4)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧