PDA

View Full Version : How to insert any user name into a file path



ma997
10-08-2013, 10:01 AM
I need to have this code work for ANY user, so instead of hard-coding my username "amta", I need to get the WINDOWS user name.

Here is the code I have:


Sub EDITSlide1()
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
objPPT.Presentations.Open "C:\Documents and Settings\amta\Desktop\Unzipped\Overview July 2013 -DRAFT_0001.pptx"
objPPT.ActiveWindow.ViewType = ppViewNormal
End Sub

Sub EDITSlide2()
Dim objPPT As Object
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
objPPT.Presentations.Open "C:\Documents and Settings\amta\Desktop\Unzipped\Overview July 2013 -DRAFT_0002.pptx"
objPPT.ActiveWindow.ViewType = ppViewNormal
End Sub

Paul_Hossler
10-08-2013, 12:17 PM
try this



objPPT.Presentations.Open "C:\Documents and Settings\" & Environ("username") & "\Desktop\Unzipped\Overview July 2013 -DRAFT_0001.pptx"


Paul

Kenneth Hobs
10-08-2013, 12:30 PM
Sub EDITSlide1()
Dim objPPT As Object, fn As String, dtPath
Set objPPT = CreateObject("PowerPoint.Application")

dtPath = CreateObject("WScript.Shell").SpecialFolders("Desktop")
With objPPT
.Visible = True
fn = dtPath & "\Unzipped\Overview July 2013 -DRAFT_0001.pptx"
If Dir(fn) <> "" Then .Presentations.Open fn
.Quit
End With

Set objPPT = Nothing
End Sub