Club Nissan Homepage
 
Forum Home Forum Home » Model Specific » Qashqai
  New Posts New Posts RSS Feed - gw2 gold VBA Macro to Create Folder if it Doesn't
  FAQ FAQ  Forum Search   Register Register  Login Login


gw2 gold VBA Macro to Create Folder if it Doesn't

 Post Reply Post Reply
Author
Message
aV3iU4sJ2f View Drop Down
Senior Member
Senior Member


Joined: 13 January 2014
Location: Maine
Status: Offline
Points: 775
Post Options Post Options   Thanks (0) Thanks(0)   Quote aV3iU4sJ2f Quote  Post ReplyReply Direct Link To This Post Topic: gw2 gold VBA Macro to Create Folder if it Doesn't
    Posted: 04 April 2014 at 11:24

VBA Macro to Create Folder if it Doesn't Exist

The Problem When attempting to save to a file path in visual basic. guild wars 2 gold The file path will not automatically be created if it doesn't exist.

Sub test() ActiveWorkbook. gw2 gold SaveAs ("C:\Test\Test.xls") End Sub

We want to save the active workbook in the folder C:\Test, if this folder doesn't exist we will receive the following error:

The Solution Check if path exists (If path exists its length will be returned, otherwise zero will be)

The End Result Sub test()

Dim Path As String

Path = "C:\Test"

If Len(Dir(Path, vbDirectory)) = 0 Then

MkDir (Path)

End If

ActiveWorkbook.SaveAs (Path "\Test.xls")

End Sub An Important Note The MkDir Function will only work if the folder proceeding the last exists

For instance if you wanted to save to the path C:\Macro\Test\Test.xls

You would have to first test if the path C:\Macro exists and if not create if before proceeding the next folder.

Sub test()

Dim Path As String

Path = "C:\Macro"

If Len(Dir(Path, vbDirectory)) = 0 Then

MkDir (Path)

End If

If Len(Dir(Path "/Test", vbDirectory)) = 0 Then

MkDir (Path "/Test")

End If

ActiveWorkbook. guild wars 2 gold SaveAs (Path "\Test\Test.xls")

End Sub Last updated on August 30, 2012
xboter 2014
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 10.11
Copyright ©2001-2012 Web Wiz Ltd.

This page was generated in 4.984 seconds.