如何在宏编程中获取当前目录名? [英] How to get current directory name in macros programming?

查看:651
本文介绍了如何在宏编程中获取当前目录名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何在宏编程中获取当前的目录变量。我正在桌面上保存文件:C:\Users\deadlock\Desktop\data.html。是否可以用当前的直接变量替换C:\Users\deadlock\Desktop\?



这是我的一小段代码:

  ActiveWorkbook.ShowPivotChartActiveFields = True 
使用ActiveWorkbook.PublishObjects.Add(xlSourceSheet,_
C:\Users\deadlock\Desktop\data.htm,Sheet1,,xlHtmlStatic,data_9438 ,)
.Publish(True)
.AutoRepublish = False

任何代码片段将非常受赞赏。



提前感谢。

解决方案

当前目录可通过VBA的 curdir()&当前工作簿的目录通过 ActiveWorkbook.Path



编辑;

  Dim current As String 
current = CurDir $()
'//根目录有一个\其他没有;标准化
如果Right $(current,1)<> \then current = current& \

使用ActiveWorkbook.PublishObjects.Add(xlSourceSheet,_
current&data.htm,Sheet1,,xlHtmlStatic,data_9438, )
.Publish(True)
....


I need to know how can i get current directory variable in macros programming. I am saving a file on desktop like this : C:\Users\deadlock\Desktop\data.html. Is it possible to replace the C:\Users\deadlock\Desktop\ with the current directly variable?

Here is my small piece of code:

 ActiveWorkbook.ShowPivotChartActiveFields = True
With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _
    "C:\Users\deadlock\Desktop\data.htm", "Sheet1", "", xlHtmlStatic, "data_9438", "")
    .Publish (True)
    .AutoRepublish = False

Any Code-snippet will highly be appreciated.

Thanks in advance..

解决方案

The current directory is available via VBA's curdir() & the directory of the current workbook via ActiveWorkbook.Path.

Edit;

Dim current As String
current = CurDir$()
'// root dirs have a \ others do not; normalize
If Right$(current, 1) <> "\" Then current = current & "\"

With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _
    current & "data.htm", "Sheet1", "", xlHtmlStatic, "data_9438", "")
    .Publish (True)
    ....

这篇关于如何在宏编程中获取当前目录名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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