用vba访问 如何读取网络中已经共享的文件夹c:\test 中的test.xls-sheet1-a1的数据?

applehoo 2008-11-14 12:51:00
用vba访问 如何读取网络中已经共享的文件夹c:\test 中的test.xls-sheet1-a1的数据?

条件:
两台都能够互访的局域网机器。
机器1:IP:192.168.0.15,是被访问的机器,计算机名:机器1。
我现在用的是另一台。机器名:机器2.
机器1上有个共享文件夹c:\test,里面有个文件test.xls

目的:我在机器2上建立了一个book1.xls,打算编辑vba去访问test.xls。然后给book1.xls-sheet1-A1赋值为test.xls-sheet1-A1.

请问如何编辑vba代码?谢谢!
...全文
1334 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
applehoo 2008-11-14
  • 打赏
  • 举报
回复
你是不是跟踪我啊。jhone99.哈哈。
jhone99 2008-11-14
  • 打赏
  • 举报
回复

Private Sub CommandButton1_Click()
Dim xlapp1 As Excel.Application
Dim xlbook1 As Excel.Workbook
Dim xlsheet1 As Excel.Worksheet

Dim xlapp2 As Excel.Application
Dim xlbook2 As Excel.Workbook
Dim xlsheet2 As Excel.Worksheet

Set xlapp1 = CreateObject("Excel.Application")
Set xlapp2 = CreateObject("Excel.Application")

Set xlbook1 = xlapp1.Workbooks.Open("\\192.168.0.200\My Webs\isosheets\035.xls")
Set xlbook2 = xlapp2.Workbooks.Open("d:\test2.xls")

Set xlsheet1 = xlbook1.Worksheets(1)
Set xlsheet2 = xlbook2.Worksheets(1)

xlsheet2.Cells(1, 1) = xlsheet1.Cells(3, 1)

xlapp2.Quit
Set xlapp2 = Nothing


xlapp1.Quit
Set xlapp1 = Nothing


End Sub
applehoo 2008-11-14
  • 打赏
  • 举报
回复
我不是要公式,是要vba代码,谢谢。
logoes 2008-11-14
  • 打赏
  • 举报
回复
如果只是这个功能,就用不着VBA了。直接在book1.xls的sheet1的A1里写公式:
='\\机器1\c\[test.xls]sheet1'!A1

2,506

社区成员

发帖
与我相关
我的任务
社区描述
VBA(Visual Basic for Applications)是Visual Basic的一种宏语言,是在其桌面应用程序中执行通用的自动化(OLE)任务的编程语言。
社区管理员
  • VBA
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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