Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/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
Excel 评估单元';将值导入路径_Excel_Vba - Fatal编程技术网

Excel 评估单元';将值导入路径

Excel 评估单元';将值导入路径,excel,vba,Excel,Vba,我在工作表(1)的A1单元格中存储了该值“ThisWorkbook.FullName” 在我的宏中,我需要获取单元格的值并在路径中对其求值,例如“D:\Users\delta\Desktop\Projects\Cars\test.xlsm” 通过执行下面的代码,我得到字符串thiswoolk.FullName。我想获得执行thiswoolk.FullName命令的结果,即当前工作簿位置的路径(字符串) 有办法吗?我在谷歌做了一些搜索,但没有成功 Public Sub try() Debu

我在工作表(1)的A1单元格中存储了该值“ThisWorkbook.FullName”

在我的宏中,我需要获取单元格的值并在路径中对其求值,例如“D:\Users\delta\Desktop\Projects\Cars\test.xlsm”

通过执行下面的代码,我得到字符串
thiswoolk.FullName
。我想获得执行
thiswoolk.FullName
命令的结果,即当前工作簿位置的路径(字符串)

有办法吗?我在谷歌做了一些搜索,但没有成功

Public Sub try()
    Debug.Print ThisWorkbook.Worksheets(1).Range("A1").Text ' this should be evaluated
End Sub

提前谢谢你

根据描述,您确实不需要计算变量,因为您可以在单元格中传递设置的值。下面是一个您可以采用的示例

Public Sub Test()
    Dim strAcDb As String
    strAcDb = strAccDBPath("Test.Accdb")
    If strAcDb = "" Then
        MsgBox "Access DB not found!", vbExclamation
        Exit Sub
    End If
End Sub

Private Function strAccDBPath(strDbName As String) As String
    If Dir(ThisWorkbook.Path & Application.PathSeparator & strDbName) <> "" Then
        strAccDBPath = ThisWorkbook.Path & Application.PathSeparator & strDbName
    ElseIf Dir(ThisWorkbook.Worksheets(1).Range("A1").Value) <> "" Then
        strAccDBPath = ThisWorkbook.Worksheets(1).Range("A1").Value
    Else
        strAccDBPath = ""
    End If
End Function
公共子测试()
作为字符串的CDB
strAcDb=strAccDBPath(“Test.Accdb”)
如果strAcDb=”“,则
MsgBox“找不到访问数据库!”,vb感叹号
出口接头
如果结束
端接头
私有函数strAccDBPath(strDbName作为字符串)作为字符串
如果目录(ThisWorkbook.Path&Application.PathSeparator&strDbName)“,则
strAccDBPath=ThisWorkbook.Path&Application.PathSeparator&strDbName
ElseIf Dir(ThisWorkbook.Worksheets(1).Range(“A1”).Value)”,然后
strAccDBPath=ThisWorkbook.Worksheets(1).Range(“A1”).Value
其他的
strAccDBPath=“”
如果结束
端函数

注意:无论如何,不要使用
Range.Text
方法,这可能会导致一些意外的结果!使用
Value
Value2
代替。

出于好奇,你为什么要尝试/需要这样做?你所说的“评估”到底是什么意思?你的代码仅仅表明你想把它打印到调试窗口。问:出于好奇,你为什么要这么做?答:我的宏将处理Access数据库(test.accdb),该数据库的名称与Excel的文件类似。默认情况下,Access文件位于包含Excel文件的文件夹中。但它可以被移动到其他地方,或者这两个文件的位置将来可能会改变。我想有一个机会,指出新的路径,以访问文件,只需编辑,无需保存路径。您可以使用
thiswoolk.Path&“\”&test.accdb
访问该文件。您似乎想在单元格A1中编写一个代码表达式,该表达式应在运行时进行计算。这是正确的理解吗?