Solved

VB Excel Macro SetCurrentDirectory issue

Posted on 2014-04-10
3
510 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 103
VB6 - Convert HH:MM into Decimal 8 53
Powershell Script need assistance to make some changes 4 63
Excel 2016 loop through 6 14
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This video teaches viewers about errors in exception handling.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now