2012-10-25 2 views
2

매크로 프로그래밍에서 현재 디렉토리 변수를 가져 오는 방법을 알아야합니다. 다음과 같이 바탕 화면에 파일을 저장합니다. C : \ Users \ deadlock \ Desktop \ data.html. C : \ Users \ deadlock \ Desktop \을 현재 직접 변수로 바꿀 수 있습니까? 모든 코드 조각은 높게 평가 될 것이다매크로 프로그래밍에서 현재 디렉토리 이름을 얻는 방법?

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

:

여기에 코드의 내 작은 조각이다. 사전에

감사합니다 ..

답변

4

현재 디렉토리가 VBA의 curdir() & ActiveWorkbook.Path를 통해 현재 통합 문서의 디렉토리를 통해 사용할 수 있습니다.

편집;

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) 
    .... 
+0

제안 된 솔루션에 맞게 코드 조각을 수정할 수 있습니까? – Mohit

+0

고마워 알렉스 .. 잘 지내 .. .. :) – Mohit

1

는 C 교체 할 수 있습니다 : 사용자 \를 \ 교착 \ 현재와 바탕 화면 \ 직접 변수?

이게 너가하려는거야?

Option Explicit 

Sub Sample() 
    Dim strPath As String 
    Dim Myar As Variant 

    strPath = "C:\Users\deadlock\Desktop\data.htm" 

    Myar = Split(strPath, "\") 

    '~~> This would give you something like 
    '~~> C:\Users\Siddharth Rout\Documents\data.htm 
    Debug.Print CurDir & "\" & Myar(UBound(Myar)) 
End Sub 
관련 문제