简体   繁体   English

通过VBA在PPT中的文本框中设置数字格式

[英]format numbers in text box in ppt via vba

I have connected Excel and Powerpoint via VBA to send values from the Excel sheet to the PPT. 我已经通过VBA连接了Excel和Powerpoint,以将值从Excel工作表发送到PPT。

All is working well except one thing: I need to transfer values from cells in Excel to text box shapes in ppt while preserving the number formatting from excel. 除一件事情外,其他所有工具都运行良好:我需要将值从Excel中的单元格转换为ppt中的文本框形状,同时保留excel中的数字格式。 How do I do that? 我怎么做?

I do this for about 10 such boxes and my current code using copy from excel and paste in powerpoint, keeps on giving out of range error on random places. 我对大约10个这样的盒子执行此操作,并且我当前的代码使用excel复制并粘贴在powerpoint中,并在随机位置上不断给出超出范围的错误。

Will paste the code I am using in a short while. 不久后将粘贴我正在使用的代码。

Try using the numberFormat from Excel when you bring over the Value . 带来Value时,尝试使用Excel中的numberFormat

Example: 例:

With Workbooks(1).Sheets(1).Range("A1")
    valueToPaste = Format(.Value, .NumberFormat)
End With

For the sake of the example, I'm pretending you are calling this from Excel and only want to know how to extract the value with it's format. 出于示例的原因,我假设您是从Excel调用此函数,并且只想知道如何使用其格式提取值。 We are using the first sheet of the first workbook in Range A1. 我们正在使用范围A1中第一本工作簿的第一张纸。 It should be easy enough to update to your specific needs. 更新您的特定需求应该足够容易。

There are probably some exceptions, particularly for custom formats, but this should work for the majority of formats you would use in Excel. 可能会有一些例外,特别是对于自定义格式,但这应该适用于您将在Excel中使用的大多数格式。

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

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