gpt4 book ai didi

vba - 如何在没有整个文件路径的情况下仅将单元格从提示中取出?

转载 作者:行者123 更新时间:2023-12-04 21:53:22 25 4
gpt4 key购买 nike

我有一个脚本,我在其中处理 2 个不同工作簿中的数据。一个是 wbVendor,一个是 wbImport。
代码是在 wbImport 中以用户形式编写的。
代码的一部分是提示用户单击 wbVendor 中的单元格。然后我需要这个选定单元格的列。现在的问题是它采用了带有工作簿整个路径的单元格。因此,不是只需要 10 美元,而是需要 '[2018 ARA 产品 list (航空公司价格).xlsx]Active Parts w Detail'!$B$10

我用于此任务的代码如下:

wbVendor.Activate
wsVendor.Activate

Set CellPN = wsVendor.Application.InputBox _
(prompt:="Click in a cell which contains the part number in the vendors file.", Type:=8)

CellPN.Select
ColumnPN = CellPN.Column

然后当我执行此代码时,会出现以下错误消息:

Run-time error '1004': Select method of Range class failed.



为了更好地理解,我附上了一张提示图片,其中包含整个文件名的单元格。

谢谢你的帮助。对此,我真的非常感激!!
Print Screen Cell Selection

最佳答案

目前尚不清楚您要在这里实现什么,但以下应该可行:

wbVendor.Activate
wsVendor.Activate

Set CellPN = wsVendor.Application.InputBox _
(prompt:="Click in a cell which contains the part number in the vendors file.", Type:=8)

CellPN.Parent.Parent.Activate 'Activate the workbook of CellPN
CellPN.Parent.Select 'Select the worksheet of CellPN
CellPN.Select 'Select CellPN

ColumnPN = CellPN.Column

AddressPN = CellPN.Address

您看到的错误是由于您在不同的工作表和/或工作簿上选择了一个单元格。
AddressPN应该包含 CellPN 的地址作为文本。

关于vba - 如何在没有整个文件路径的情况下仅将单元格从提示中取出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49980071/

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