Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ActiveWorkbook.SaveAs in /TMP?

Posted on 2016-09-21
3
Medium Priority
?
59 Views
Last Modified: 2016-10-13
Please forgive what may be astonishing ignorance.

On a PC, it works, but I can't get it to work on a Mac - Goal is to save a temporary Excel with macros file (so it will be deleted thereafter) with a standardized name for emailing. I'd like to do so in the TEMP directory. Here it is for the PC:

ActiveWorkbook.SaveAs Filename:=Environ("temp") & "\" & Range("J112").Text & " - MCR " & Range("D112").Text, _
         FileFormat:=52, CreateBackup:=False

I've tested various combinations without success. What to do?
Thanks!
0
Comment
Question by:Dave Evans
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Koen
ID: 41809796
i don't know how the save command needs to work on a mac...but good practice for debugging is creating a variable for your filename and save on the next line.
then when you step through your code, you can inspect the actual value of your MyFilename variable before the error hits...

Also when adding cell content to a filename you should consider error handling for illegal characters
I always use a function for that (that I found here on EE)

Function strLegalFileName(strFileNameIn As String)

'this function removes all illegal characters from a String used as sheetname and filename

    Dim i As Integer
    
    Const strIllegals = "\/|?*<>"":"
    strLegalFileName = strFileNameIn
    For i = 1 To Len(strIllegals)
        strLegalFileName = Replace(strLegalFileName, Mid$(strIllegals, i, 1), "_")
    Next i
End Function

Open in new window

0
 
LVL 14

Accepted Solution

by:
Zack Barresse earned 2000 total points (awarded by participants)
ID: 41809818
It won't work on a Mac, because there is no folder like that. Think about utilizing another folder. Here is a good place to find code to get special folders on a Mac:

http://rondebruin.nl/mac/mac007.htm

HTH

Regards,
Zack Barresse
0
 
LVL 14

Expert Comment

by:Zack Barresse
ID: 41841647
Without additional information from the OP, this is the most succinct answer available.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

886 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