简体   繁体   English

Excel 将数字键盘的“,”更改为“。” 使用 VBA 的“printpreview”打印范围后

[英]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.我正在处理一个 Excel 文件,该文件提供了一些工作表来计算不同的内容。 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:此按钮背后的代码存储在“Table1”中,如下所示:

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.打开文件后,我可以在选择的单元格中输入类似“1,4”的内容,一切正常。 My problem starts when printing the summary via VBA code (see above).我的问题是通过 VBA 代码打印摘要时开始的(见上文)。 After this, pressing my NumPad's "," results in getting a "."在此之后,按我的 NumPad 的“,”会得到一个“。” 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.如果我在打印后不小心使用了 NumPad,在单元格中键入“1.4”并按 Enter,该单元格将获得用户定义的格式为日期(01.04。或者在您的情况下可能是 01/04 或其他)并且使所有内容崩溃。

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.我用 Excel 2010 和 2016 检查了文件,两种情况下都出现了问题。

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.我还尝试过在打印前后检查 Excel 的选项,但没有任何改变。

My guess:我猜:

There might be a problem with Excel-VBA's "PrintPreview" in general.一般而言,Excel-VBA 的“PrintPreview”可能存在问题。 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:提供的解决方案将代替Worksheets("Table5").PrintPreview使用:

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.所以我仍然更愿意使用第一个建议并设置 DecimalSeperator。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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