本文介绍了相对而不是Excel VBA中的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了一个Excel VBA宏,它在对数据进行计算之前从HTML文件(本地存储)导入数据。



当前HTML文件是引用绝对路径:

  Workbooks.Open FileName:=C:\Documents and Settings\Senior Caterer\\ \\ My Documents\Endurance Calculation\TRICATEndurance Summary.html

然而,我想使用一个亲戚指向它而不是绝对路径(这是因为我想将电子表格分发给可能不使用相同文件夹结构的同事)。由于html文件和excel电子表格都位于同一个文件夹中,我不会认为这将是困难的,但是我完全无法做到这一点。我在网上搜索,建议的解决方案都显得非常复杂。



我在工作中使用Excel 2000和2002,但是随着我计划分发,我会希望它可以使用尽可能多的Excel版本。



任何有意见的建议。

解决方案

只是为了澄清什么yalestar说,这将给你相对的路径:

  Workbooks.Open FileName:= ThisWorkbook.Path& \TRICATEndurance Summary.html


I have written an Excel VBA macro which imports data from a HTML file (stored locally) before performing calculations on the data.

At the moment the HTML file is referred to with an absolute path:

Workbooks.Open FileName:="C:\Documents and Settings\Senior Caterer\My Documents\Endurance Calculation\TRICATEndurance Summary.html"

However I want to use a relative path to refer to it as opposed to absolute (this is because I want to distribute the spreadsheet to colleagues who might not use the same folder structure). As the html file and the excel spreadsheet sit in the same folder I would not have thought this would be difficult, however I am just completely unable to do it. I have searched on the web and the suggested solutions have all appeared very complicated.

I am using Excel 2000 and 2002 at work, but as I plan to distribute it I would want it to work with as many versions of Excel as possible.

Any suggestions gratefully received.

解决方案

Just to clarify what yalestar said, this will give you the relative path:

Workbooks.Open FileName:= ThisWorkbook.Path & "\TRICATEndurance Summary.html"

这篇关于相对而不是Excel VBA中的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 07:53