简体   繁体   中英

Excel changes NumPad's "," to "." after printing a Range with VBA's "printpreview"

The situation:

I am working on an Excel file that offers some worksheets to calculate different things. The last of these worksheets is a summary of all the others that is preformatted for perfect printing on a standard paper sheet. I want to print this summary by clicking a button on the main page (first worksheet). The code behind this button is stored in "Table1" and looks like this:

Sub Print()

Worksheets("Table5").PageSetup.PrintArea = "B2:N48"
Worksheets("Table5").PrintPreview

End Sub

The problem:

I've got a german Keyboard with "," as decimal separator on the NumPad. My whole system uses the "," as this. After opening the file, I can just enter something like "1,4" in a cell of choice and everything works. My problem starts when printing the summary via VBA code (see above). After this, pressing my NumPad's "," results in getting a "." instead. The standard "," of the keyboard still works as supposed.

If I accidentially use the NumPad after printing, type "1.4" in a cell and hit Enter, the cell gets a user defined format as date (01.04. or in your case propably 01/04 or something else) and crashes everything.

What I tried:

I made a simple test file with only the two code lines above and just a blank space to print. I found out, that the problem only appears, if I really print the summary. Starting the preview and then cancelling it before printing does not cause the problem.

I checked the file with Excel 2010 and 2016 and the problem appeared in both cases.

If I save the file, close it and open it again, the problem is gone, but new formatted cells will stay and crash the file.

What I also tried is checking Excel's options before and after printing, but nothing changed.

My guess:

There might be a problem with Excel-VBA's "PrintPreview" in general. It would be nice to get a confirmation of my problem, a solution for it or a workaround. I cannot change the printing process to standard printing, because my real file is much more difficult.

Best wishes

RaspiManu

I was able to recreate the problem. The odd thing is that under File > Options > Advanced the decimal seperator symbol will still show as the comma. However the problem gets fixed with:

Application.DecimalSeparator = ","

Which would set the decimal seperator to the comma again.


Edit , I guess it's a known bug as I found this question on the same issue here. A solution provided there would be instead of Worksheets("Table5").PrintPreview use:

Application.CommandBars.ExecuteMso "FilePrintPreview"

However for this option to work, the activesheet needs to be the one you want to print from. So I would still prefer to use the first suggestion and set the DecimalSeperator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM