runtime error 1004 saveas text file

J

Janis

I get a runtime error on the activeworkbook.saveas line.

Sub saveIndesign()
'Appends date to filename so as to not write over an existing file

' saveIndesign Macro

Const fPath As String = "Mac OS X:Users:jrough:Documents:"
Dim fName As String
Dim myFileName As String
myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) & Date
& ".txt"

fName = fPath & myFileName & time()
ActiveWorkbook.SaveAs Filename:=fName, FileFormat:=19
MsgBox "File Saved to " & fName
End Sub


I checked that the diretory is read/write, the filename & path is under 200
characters, the name isn't already created. That is why I would like the
time appended to the filename and the date.

Thanks,
 
D

Dave Peterson

In the windows world, we can't save files that have /'s or :'s in their names.
Is that a problem on the Mac?

If it is, maybe:

myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) _
& format(Date,"yyyymmdd") & "_" & format(time,"hhmmss") & ".txt"

or just
myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) _
& format(now,"yyyymmdd_hhmmss") & ".txt"

ps. watch your order of stuff.
This line in your original code:
fName = fPath & myFileName & time()
would end up with .txt followed by the time.

I bet that isn't what you wanted.

pps. There are some mac users here (and lots of code is the same), but if you
have mac related questions, you may find that you get more attention in this
newsgroup:
news://msnews.microsoft.com/microsoft.public.mac.office.excel
 
J

Janis

Thanks,



Dave Peterson said:
In the windows world, we can't save files that have /'s or :'s in their names.
Is that a problem on the Mac?

If it is, maybe:

myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) _
& format(Date,"yyyymmdd") & "_" & format(time,"hhmmss") & ".txt"

or just
myFileName = Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4) _
& format(now,"yyyymmdd_hhmmss") & ".txt"

ps. watch your order of stuff.
This line in your original code:
fName = fPath & myFileName & time()
would end up with .txt followed by the time.

I bet that isn't what you wanted.

pps. There are some mac users here (and lots of code is the same), but if you
have mac related questions, you may find that you get more attention in this
newsgroup:
news://msnews.microsoft.com/microsoft.public.mac.office.excel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top