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