如何将当前目录指定为VBA中的路径 [英] how to specify current directory as path in VBA

查看:121
本文介绍了如何将当前目录指定为VBA中的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个支持宏的工作表。我需要指定启用宏的文件的当前文件夹作为路径。我尝试设置

  path = ActiveWorkbook.Path 

  path = CurDir()

这两个都不适合我。任何想法这个??

解决方案

我以为我误会了,但我是对的。在这种情况下,它将是 ActiveWorkbook.Path



但主要问题不在这里。问题是这两行代码

  strFile = Dir(strPath&* .csv)

哪些应该写为

  strFile = Dir(strPath&\ * .csv)

/ p>

  With .QueryTables.Add(Connection:=TEXT;& strPath& strFile,_ 

哪些应该写为

  With .QueryTables.Add(Connection:=TEXT;& strPath&\& strFile,_ 


I have a macro enabled sheet. I need to specify the current folder in which the macro enabled file is present as the path. I tried setting

     path = ActiveWorkbook.Path  

and

     path = CurDir()  

Both of these doesn't work for me. Any idea on this??

解决方案

I thought I had misunderstood but I was right. In this scenario, it will be ActiveWorkbook.Path

But the main issue was not here. The problem was with these 2 lines of code

strFile = Dir(strPath & "*.csv")

Which should have written as

strFile = Dir(strPath & "\*.csv")

and

With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, _

Which should have written as

With .QueryTables.Add(Connection:="TEXT;" & strPath & "\" & strFile, _

这篇关于如何将当前目录指定为VBA中的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆