Solved

VB Excel Macro SetCurrentDirectory issue

Posted on 2014-04-10
3
512 Views
Last Modified: 2014-04-10
With the following coding below we are trying to have the coding save the CSV save in whatever directory the file is in and not have the path hard coded.

We are also trying to get this to work with 64-bit.  Any assistance offered would be greatly appreciated.

Sub Write_CVS_XLS()
    Application.DisplayAlerts = False

'
' Write_CVS_XLS Macro
' Writes CVS file then saves XLS file
'

'
    ActiveWorkbook.SaveAs Filename:= _
        "F:\Cadd\Blocks\New Titleblock\Title_Frame_Register.csv", FileFormat:=xlCSV, _
        CreateBackup:=False
    ActiveWorkbook.SaveAs Filename:= _
        "F:\Cadd\Blocks\New Titleblock\Title_Frame_Register.xls", FileFormat:= _
        xlExcel8, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
    Application.DisplayAlerts = True
   
End Sub
0
Comment
Question by:regsamp
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 39991415
Just use the Path property of the current workbook;
ActiveWorkbook.SaveAs Filename:= _
        Activeworkbook.path & "\Title_Frame_Register.csv", FileFormat:=xlCSV, _
        CreateBackup:=False

Open in new window

0
 

Author Comment

by:regsamp
ID: 39991420
Okay, let me try that Graham.
0
 

Author Comment

by:regsamp
ID: 39991472
It worked perfectly, thank you.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question