wrong PDF output size with ExportAsFixedFormat in Excel VBA - vba

I use Excel 2010 with VBA.
I have the following code :
mySh.PageSetup.PaperSize = xlPaperLetter
mySh.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=filePathTmp, _
Quality:=xlQualityStandard, IncludeDocProperties:=False, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
It generates a PDF without error but the size is not correct.
I get a 22.26 x 28.80 cm instead of the 21.59 x 27.94 cm that I would like to obtain.
Any ideas ?
Thanks for your help

I use Excel 2010 and had this problem. I fixed it by changing the printer in Excel's dropdown list on the Print section of the File tab. My default printer is a Konica Minolta copy machine. I changed it to Local Printer (which doesn't actually exist) and it worked! I now have the VBA code returning an 8.5x11 PDF! Now I don't have to use our clunky old laptop with an old Office to get the right size.
Note that picking the Adobe PDF printer did not fix the problem. Just try messing with the different printer choices, or make a fake printer in your computer's Devices and Printers and use that. I hope it works for others with the same issue!

I set the print area where I wanted it: View-Page Break Preview.
Then File-Print-Scaling = Fit Sheet on One Page
Or
File-Print-Page Setup-Fit to: 1 pages wide by 1 tall.
Hope it helps someone.

I also use Excel 2010 and had the same problem. When using ExportAsFixedFormat, the page won't scale. From what I understand, it is the same as using the Save As with file type pdf. This means that you need to need to scale your workbook to fit the page that you require.
If you:
-Open printer settings and select 'No Scaling'
-Page Layout > Print Area > Clear Print Area
-Select View > Page Break View
It will show you the page area. If you scale your worksheet to this it will save to pdf using ExportAsFixedFormat properly.

We had the same problema and soved it changing at devices and printers the default printing options:
-Control Panel->Devices and Printers->Select the printer by clicking once to it.
-Second mouse button->Printer properties->Advanced->Printing defaults->Advanced.
-Choose paper size and click OK.
Why not to change it at excel? Because somthing related to permissions between Excel and the service running spool or...
That default setting makes the macro to export to the paper size correctly.
If it Works for you, is thanks to our IT department, not to me :P

Related

Adding watermarks to exports

I have several access databases that I export out of either in Excel or PDF. Now I am told that i need to add watermark to all of my exports. However, I am not sure if this is possible or if it can be done. Do you know how I can add a watermark to a an export out of access saved as PDF or Excel file.
I created code to export to excel and email the file. I also created an add-in in excel that inserts the watermark. I dont know how to use together.
This is the code I am using to export to excel and email:
Function ExportDailyPayoffs()
Dim dtemnyr As String
Dim mondt As String
If Weekday(Date) = vbMonday Then 'Check to see if its Monday
dtemnyr = Format(Date - 3, "mmddyy") 'We want to get the file for Friday
Else
dtemnyr = Format(Date - 1, "mmddyy") 'We want to get the file for Friday
End If
DoCmd.SendObject acSendQuery, "A1 Daily Payoffs", acFormatXLSX, "CLSS#xxxx.US", , , "Daily Payoff Report - " & dtemnyr, "Enclosed please find the Daily Payoff Report", True
End Function
I want the word(watermark) CONFIDENTIAL to be in the excel when it gets exported out of access or email to anyone.
Adding a watermark to a .pdf output is straightforward. In design view, a report has a Picture property. That picture can be a watermark, created as a graphic file. The watermark is under all of the text, borders, etc., as if it's part of the paper on which the report is being printed, but to see the watermark properly you need to set the controls' background to transparent. If the watermark is a fairly unsaturated (pastel) color, then the text will be quite readable over the watermark.
Adding a watermark to Excel output is harder. I know of no way to do it directly within Access. I recently needed to do something similar, reformatting Excel output to modify column widths, let selected columns' contents wrap, and so on. I did it by writing an Excel workbook to do the reformatting of the exported workbook. Immediately after I export a workbook, the VBA code which exports it then opens the reformatting workbook, which auto-executes to perform its work and then closes itself. This isn't the right place to explain all of the details, but that's the general approach.

Wrong barcode exported from Visual Basic Macro in MS Word to PDF

I am trying to export through a Macro in MS Word a String that has 4 numbers. The whole Macro runs just fine, but, when I open the resulting PDF, I see that the barcode displayed seems corrupt.
This is the result:
In the Macro, I select the text I want to format, and change the font to "Free 3 of 9 Extended".
I have tried wrapping this number with "*" characters without success. Also tried "!". None of this seems to work. The funny part is that, if I open a Word document and type the same numbers using the same font, a clear Barcode is displayed:
This is what I see when writing directly in MS Word the same characters using the same font,this is what I see (which is what I want to achieve in the PDF export).
My macro exports to PDF with the following code:
Public Function guardar(id As String) As String
Dim path As String
guardar = id
obj_Word.ActiveDocument.ExportAsFixedFormat OutputFileName:=guardar,
OptimizeFor:=wdExportOptimizeForPrint, UseISO19005_1:=True,
IncludeDocProps:=True, KeepIRM:=True, ExportFormat:=wdExportFormatPDF
End Function
Is it possible that the template you are given is setting the font weight to bold in that portion of the document in which you are introducing the barcode, thus modifying the way it is displayed?
I cannot think of any other reason. The code you are posting does not seem to be the culprit.

VBA equivalent to Save As Picture in PPT

I am trying to use vba to save grouped shapes as an image in powerpoint. The "save as picture" function that you can use by right clicking on the group produces high quality images. My attempt to recreate the right-click function produces blurry, low quality images. Is there a way to exactly recreate the right click save as picture instead of export?
ActivePresentation.Slides(1).Select
Call ActiveWindow.Selection.ShapeRange(1).Export( _
"C:\myloction.png", _
ppShapeFormatPNG)
Add optional scaleheight/scalewidth parameters after the ppShapeFormat parameter. The results seem almost random, I don't know exactly what the parms are supposed to relate to, but the bigger the number you feed it, the higher the rez of the exported image.

Dymo Labelwriter SDK Not Printing Correctly

I have created an application in VB.Net using Dymo's SDK for printing labels. Some of the users are using the 450 model, and some are using the 450 Twin Turbo. I have set it up to print the contents of a textbox, including a procedure to determine if the user is using the Twin Turbo or not, and which label size to print to if so.
Anyways, this all seems to work fine on my system, but the problem I'm facing is that the actual users of the application also occasionally use Dymo Label v.8, and when they go to use my application, it will print whatever the last label was that they created in Label v.8, rather than the label in the application that I made.
I could be wrong, but my assumption is that the old label is hanging up in some kind of memory queue somehow, and I just need to clear it from memory. (I know, I'm not using the proper terminology... I speak gooder English, I promise. In case it's not obvious at this point, I've never heard of Dymo Labelwriter or the SDK until this project)
Here's my printing Sub:
DymoAddIn.StartPrintJob()
If GlobalVariables.label = "Left" Then 'Determine if printing on small spool
DymoLabels.SetField("Address", TextBox.Text) 'Applies content of textbox to label
DymoAddIn.Print2(1, False, 0) 'Prints on the left spool
Else
DymoLabels.SetField("Address", TextBox.Text)
DymoAddIn.Print2(1, False, 1) 'Prints on the right spool
End If
DymoAddIn.EndPrintJob()
I assumed that EndPrintJob() would clear everything, but maybe I'm completely misunderstanding.
How can I stop the label writer from printing an old label that has nothing to do with my program? Why is it acknowledging the labels I make on my system and printing those, but not the ones that the actual clients use?
Ideas?
And if I'm missing key information that would help, please let me know.
Thanks.
Nevermind, I figured it out. Instead of "0" or "1", it's actually "Left", "Right", or "Auto". After that, it just required a bit of fiddling, and I got it done.

Print to POS Display Unit

I have an Epson Display Unit (for the Point of Sale), and have it set up as a printer. I can only get it to print what I want when I go to Printer Properties > Fonts (there is a test input box).
However printing from an app such as notepad yields no results. I'm trying to get it to work with the p.o.s. app I made in Excel. I found a COMM port communication script here, but I can't get past the OPEN command. Seems there's a "file in use". I'd like to know if anyone else has had experience with this sort of thing.
Under the assumption that your printer is connected to serial interface 1, provided that the serial interface parameters are correctly set, and you want to send a string of characters to that interface, you may try this ...
Sub WriteToCOM()
Open "COM1:" For Output As #1
Write #1, "ddd"
Close #1
End Sub
Paste this code into an Excel VBA script and cycle thru it with F8 - it worked for me
You may replace "COM1:" by any existing "COMx:" or "LPTx:" as well (don't forget the semicolon!)
I am using this to control an Amateur Radio (setting the frequency) from an Excel table containing broadcast station names and their frequencies. I am of course sending special characters to my gear using the chr() function.
The Macro is tied to a control button. My Excel is Office 2003 (it worked already in Office97)
Good luck
MikeD