Solved

ActiveWorkbook.SaveAs in /TMP?

Posted on 2016-09-21
3
21 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 8

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

706 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

22 Experts available now in Live!

Get 1:1 Help Now