I have an excel file with the script that allows me to generate seperate pdfs according to the data i enter into one spreadsheet. However, the code was created using Windows, and I would like to use it in mac. Can anyone help with changing the pathname of the script? The script is as follow:
Sheets("6 comp").Activate
Range("$I$93").Value = i
ActiveSheet.Calculate
ClientName = Range("$I$94").Value
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:="C:\test\" & ClientName & "_6", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Thank you so much!!
Unfortunately, it's not as easy as changing the filename path in this case.
I stripped out the specifics to your situation and got it to work fine on Windows. But when I first ran it on my Mac, it send the PDF right to my default printer instead of saving the file to any location.
Consistently, any attempt to edit the script on my Mac resulted in Runtime Error 1004 (even after changing back to the original code). I believe this is a bug, but there are also a lot of unsupported features on the Mac, and many are not documented by Microsoft.
Ron de Bruin's website for Mac/Windows Office topics has a great writeup on how to save a PDF in Excel Mac. http://www.rondebruin.nl/mac/mac005.htm If you really need to get this working, that page should help.
I'd much prefer to give you a straight answer, but if you look at that page, you'll see how complicated it is.
Related
I have a number of questions on this topic:
If I print using Application.ActivePrinter = "Microsoft Print to PDF on Ne01:" then how can I pass a specific file name and path to the printer? (Rather than having it prompt me?)
Since I want others to use this file, how can I check that Microsoft PDF is always on Ne01? What if theirs is on a different port?
Many suggest using a Findprinter command, but I always get the sub or function not defined error
Many suggest using the built-in ability to save as a PDF, instead of printing to PDF, but I find the resulting PDF has huge margins and the wrong size (not A4)
You can save Excel sheets as PDF directly. Try below macro. Change C:\ to save your file to your desired location.
Sub SavePDF()
Dim pdfName As String
pdfName = "MyFileName"
Sheets("MyPDFsheet").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\" & pdfName & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=True, _
OpenAfterPublish:=False
End Sub
PDF printouts go to a "Port" that port can have a filename same as any printing device. The user normally is tasked with select device/folder/portname.pdf thus there is a virtual PORTPROMPT: device (that is set via the print prompt dialog)
A) Set a duplicate driver to a port as a fixed filename in a watch folder. see Print to PDF with powershell while suppressing the "Save As" Prompt and https://stackoverflow.com/a/69169728/10802527
A) You cannot, this Windows 11 just Like Other Windows versions currently does not have an MS PDF printer, it is a windows optional extra I am not allowed to install.
A) Too variable, Default 1st NEtwork printer may be a Fax or in this case nothing so should return NULL
A) Save should have options. see https://superuser.com/questions/1064214/create-pdf-from-an-excel-file-without-white-margins for other suggestions, However for PDF Print there are many reasons for no fixed size, Windows will keep changing printers to "last used" unless told other wise, and last used can be any paperkind or margins.
However, In my case I frequently set default to my region (A4 Portrait) and as often as I can I set "No margins" but windows Edge will frequently reset that to big "Default". Perhaps I should set default to A4zerOmargin
first time posting but have learned so much in this place already! Now there's an issue for which i do not find a way out..
I have an excel sheet with a bunch of userforms which is used for invoicing. In one of the userforms, the user has the possibility to print the invoices.
All code runs fine up to the line:
fname = Application.GetSaveAsFilename("", "PDF Files (*.pdf), *.pdf")
Then the computer freezes, and Microsoft Excel is apparently using >60% of the processor capacities. After many minutes the "save as" window finally pops open, and all works perfectly again.
I've tried going around this issue and printing to pdf instead of saving to pdf, but the same happens on the line:
If Application.Dialogs(xlDialogPrinterSetup).Show = True Then
ActiveWindow.ActiveSheet.PrintOut
End If
Is there any known issue with this code on weaker computers? All code works fine on my computer, but not on the user's pc.
I've built in stops, and msgboxes on the other parts of the code, just in case the issue would be elsewhere, but it's really only on these lines that the computer panics.
Thanks a lot in advance for any advice!
I am currently in the process of writing a VBA macro at work however I have run into a problem which I am hoping you can help me with.
All I am trying to do is simply run an applescript app from excel, this was very easy to do in the 2011 version but has seemingly gotten a lot more complicated in the 2016 edition.
I have researched various places online but with no luck, the only articles and guides I have come across point towards parameters and checking files but unfortunately I have no idea what any of those are. All I would like to do is to provide the filepath of the applescript so that excel can run it, is these even possible anymore?
I have attached the relevant applescript file, please don't judge me too hard for how bad it is, I only started learning last week.
The code that worked in Excel 2011 was as follows:
OSA = "/usr/bin/osascript"
SCRIPT = "/users/savePDF.scpt"
MacScript ("do shell script " & Chr(34) & OSA & " " & SCRIPT & Chr(34))
However in excel 2016 I am trying to use the AppleScript task command but get a compile error that the argument is not optional. Although I am not sure what argument they are talking about
Many thanks for all your help.
Seems like such a stupid question now I've finally figured out the answer.
Seeing as I didn't to control any variables or pass any values back and forth between applescript and VBA, the applescripttask command was pretty useless for me.
I ended up being able to launch the ".app" by simple using the hyperlink command, as follows:
ActiveWorkbook.FollowHyperlink Address:="/Users/(usernamehere)/Desktop/savePDF1.app", NewWindow:=True
I'm porting some VBA from Excel 2003 (Windows XP) to Excel 2004 (OS X). Excel 2004 contains a VBA interpreter that allows you to fob off some commands onto Applescript using the MacScript() function.
This is all well and good for what I want to do (which is to launch files in their default application, something which on the Windows version uses an API call and is obviously incompatible with the Mac version). The code I'm using to generate the Applescript is as such:
sScript = "set filepath to POSIX path of """ & path & """" & Chr(13)
sScript = sScript & "try" & Chr(13)
sScript = sScript & "set command to ""open "" & quoted form of filepath" & Chr(13)
sScript = sScript & "do shell script command" & Chr(13)
sScript = sScript & "end try"
MacScript(sScript)
Now everything I've done and read tells me that this ought to work. It works when I run it from the Applescript Editor. And yet, it always fails, no matter what. And what is clearly failing is the "POSIX path" part. It throws a generic Error 5, "Invalid procedure call or argument," which isn't very enlightening.
This seems rather essential to its operation, and I've found zero evidence that other people have had this trouble before me. It's driving me mad. "POSIX path" seems a standard part of the Applescript definition, yet it always fails here. (It converts the file from Macintosh HD:Users:MyUserName:Blah to /Users/MyUserName/Blah.)
Does anyone have any suggestions? I'm thinking that I'll just need to write my own POSIX path function in VBA to make it work with this code, if the MacScript() function refuses to do it on its own. But I'm wary about parsing strings and etc. regarding a function I only halfway understand (the above case is easy, obviously, but I don't know how complicated it could get).
You don't need to do this using a shell command and can then avoid using "posix path". Try this...
tell application "Finder" to open file path
I have an XLA file that is to be deployed to a number of users in the organisation as an Excel add-in. My intention is to deploy it to a directory in the user's "documents and settings" folder in "Application Data\MyCompany". (In fact this is all working through a wrapper that copies the latest version of the XLA locally and installs it as an Excel add-in).
However, if a user creates a sheet that references a function defined in this XLA then Excel appears to store the absolute path of the XLA in the function call. Thus, if the user sends the sheet to a colleague Excel fails to resolve the function as their copy of the XLA resides at a different absolute path (as their username is part of the absolute path).
My belief up until now was the Excel "just coped" with this as long as the XLA was installed as an add-in but this does not appear to be the case.
Is it really the case that I need to enforce an identical absolute path for my add-in for all users? This is possible within a single organisation but I honestly can't believe this is true as it seriously impedes sharing of XLS files.
Thanks.
There's no good way to do this. I put my xla files on a network share rather than locally and install them via the UNC path. That only works for me because everyone has access to the share, which may not be the case for you. Here's some other alternatives
http://www.dailydoseofexcel.com/archives/2008/06/02/fixing-links-to-udfs-in-addins/
I simply remove the path with a sub like this one:
Sub RemoveXlaPath()
'
' Goal: delete the path reference to the add-in, i.e. everything before and including the '!'
' ='C:\Program Files (x86)\Microsoft Office\Office14\LIBRARY\populator.xlam'!famedata(...)
'
Cells.Replace What:="'C:\*xla*'!", Replacement:="", _
LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _
SearchFormat:=False, ReplaceFormat:=False
End Sub
Can you specify an environment variable-based path? E.g. %APPDATA%\MyCompany
What I have done is if I give a user a XLS , it has in its on open event some code which - installs the the XLA as part of its on open event. It also uninstalls old version if any (delete and command bars). This self distributes. In theory it could clean up any paths. This assumes there is some shared drive which everyone can access, this prevents them copying the XLA to local drive. Alternatively email them a shortcut to the XLA with XLA on the shared drive. If possible you don't want an XLA on a local drive.
If the XLA must be on a local drive - not sure if this would work but an XLS on open event could check an fix any paths and install /install a xla - if it knows where its is. But if you were emailing a XLS over the internet, the on open event of the XLS could check if the XLA is available and put up a message box telling the user what to do - install this xla, which would be a separate attachment. The XLA could clean up any paths as part of its on open event - just some ideas.
another possibility is the XLA on open event can modify the XLSs on open event so that if that XLS is distributed the XLS will be able to check if the XLA is available. Tricky.
It's a poor oversight that makes add-ins barely manageable for shared use. Other than this, using .XLAM add-ins is a good way to avoid having to have macro-enabled spreadsheets (the shared spreadsheet can be distributed without macros and the macros can reside in an .XLAM)