gpt4 book ai didi

vba - 错误 "91"未设置对象变量或 With block 变量

转载 作者:行者123 更新时间:2023-12-02 20:37:16 25 4
gpt4 key购买 nike

我正在尝试使用函数参数之一设置单元格的值。代码给出错误 91。代码中的第 6 行引发错误:

提前致谢。

Sub report_file(a, r_row)
Dim wb_dst As Workbook
Dim ws_dst As Worksheet
Set wb_dst = Workbooks.Open("F:\Projects\vba_excel\report.xlsx")
ws_dst = wb_dst.Sheets(1)
ws_dst.Cells(r_row, 2).Value =a
End Sub

错误行是:

ws_dst.Cells(r_row, 2).Value =a

最佳答案

Option Explicit

Sub report_file(a, r_row)
Dim wb_dst As Workbook
Dim ws_dst As Worksheet
Set wb_dst = Workbooks.Open("F:\Projects\vba_excel\report.xlsx")
Set ws_dst = wb_dst.Sheets(1)
ws_dst.Cells(r_row, 2).Value = a
If a = "savior" Then
wb_dst.Cells(r_row, 2).Value = a
End If
End Sub

关于vba - 错误 "91"未设置对象变量或 With block 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16443584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com