VBA不用打开excel文件就可读写单元格数据

更新时间:2024-01-23 04:36:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

VBA不用打开excel文件就可读写单元格数据 使用WPS时编的

在第一个工作薄添加CommandButton3按钮添加代码如下:

Private Sub CommandButton3_Click() Dim Wb As Workbook

Set Wb = GetObject(\项目设计\\操作表\\联系2.xls\ Wb.Sheets(1).Range(\

Workbooks(1).Sheets(1).Range(\ Dim str As String

str = Wb.Sheets(1).Range(\ MsgBox (str)

Wb.Sheets(1).Visible = xlSheetVisible Wb.Save Wb.Close True Set Wb = Nothing

End Sub

在第一个工作薄“Workbooks(1)”添加按钮

CommandButton1,添加如下代码:

Private Sub CommandButton1_Click()

Dim Wb As Workbooks

fileToOpen = Application.GetOpenFilename(\

If fileToOpen <> False Then

Workbooks.Open Filename:=fileToOpen, AddToMru:=True MsgBox (Workbooks(2).Name)

‘使用按钮CommandButton1打开第二个工作薄,因此是Workbooks(2)

Windows(Workbooks(2).Name).Visible = True '取消隐藏,因文件已打开因此使用windows()函数

If Workbooks(2).ReadOnlyRecommended = True Then Workbooks(2).ReadOnlyRecommended = False '取消只读 End If Else End If

End Sub

本文来源:https://www.bwwdw.com/article/8x7o.html

Top