Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用变量调整工作表的尺寸_Vba_Variables_Excel - Fatal编程技术网

Vba 使用变量调整工作表的尺寸

Vba 使用变量调整工作表的尺寸,vba,variables,excel,Vba,Variables,Excel,我有一个工作表,其中有一个单元格=我想作为变量调暗的文件夹的名称。我要做的是设置cell=filename变量。查看我的代码可能会更容易。我目前在我的“设置输入1”上得到了“object required error”,我设置变量的方法也可能是错误的 Dim WbkA As Workbook Dim Input1 as string Set Input1 = Workbooks.Open(Filename:="G:\Reporting\ReportCompare.xls").worksheet

我有一个工作表,其中有一个单元格=我想作为变量调暗的文件夹的名称。我要做的是设置cell=filename变量。查看我的代码可能会更容易。我目前在我的“设置输入1”上得到了“object required error”,我设置变量的方法也可能是错误的

Dim WbkA As Workbook
Dim Input1 as string

Set Input1 = Workbooks.Open(Filename:="G:\Reporting\ReportCompare.xls").worksheets("Sheet4").Range("A4").Value
Set wbkA = Workbooks.Open(FileName:"Input1")

您尝试将关键字为
Set
的对象引用分配给数据类型(字符串


删除关键字
Set
,一切都会好起来。

您尝试将带有关键字
Set
的对象引用分配给数据类型(字符串


删除关键字
Set
,一切都会好起来。

代码需要稍微重新排序才能突破步骤

  • 从工作簿中获取文件路径和名称,并将其存储为字符串 变量(Input1)

  • 使用字符串变量(Input1)中存储的值打开文件

  • 将对打开文件的引用设置为对象变量(WbkA)

下面列出的是代码

Sub test()

Dim Input1 As String
Dim WbkA As Workbook

  Input1 = Worksheets("Sheet4").Range("A4").Value 'Get the path and file name
  Workbooks.Open Filename:=Input1  'Open the file
  Set WbkA = ActiveWorkbook 'Set the reference to the workbook

  MsgBox WbkA.Name 'Show the name value from the object.

End Sub

代码需要稍微重新排序,以便突破这些步骤

  • 从工作簿中获取文件路径和名称,并将其存储为字符串 变量(Input1)

  • 使用字符串变量(Input1)中存储的值打开文件

  • 将对打开文件的引用设置为对象变量(WbkA)

下面列出的是代码

Sub test()

Dim Input1 As String
Dim WbkA As Workbook

  Input1 = Worksheets("Sheet4").Range("A4").Value 'Get the path and file name
  Workbooks.Open Filename:=Input1  'Open the file
  Set WbkA = ActiveWorkbook 'Set the reference to the workbook

  MsgBox WbkA.Name 'Show the name value from the object.

End Sub

首先也是最重要的一点,谢谢你;这让我通过了变量部分,但现在Set wbkA=Workbooks.Open(filename:=“test”)给了我一个错误。我觉得我应该把“test”以外的东西放在它所在的位置,但不知道它是什么。有什么想法吗?方法Workbooks.Open等待一个文件名作为参数(更多详细信息如下:)如果您使用上述变量,请首先使用
Workbooks.Open Input1
谢谢;这让我通过了变量部分,但现在设置wbkA=Workbooks.Open(filename:=“test”)给了我一个错误。我觉得我应该放一些“test”以外的东西“在它所在的地方,但不知道是什么。有什么想法吗?方法Workbooks.Open将文件名作为参数等待(此处更详细:)如果使用上述变量,请使用
Workbooks.Open Input1
+1。您只需执行
Set wbkA=Workbooks即可。打开文件名:=Input1
尽管:)+1。您只需执行
Set wbkA=Workbooks即可。打开文件名:=Input1
不过:)