简体   繁体   English

VBA-在Excel中漂亮地打印一行

[英]VBA - Pretty Print a Row in Excel

I want to print a row in Excel. 我想在Excel中打印一行。 One row contains data for one project. 一行包含一个项目的数据。

I want to print one row on one page nicely formatted. 我想在格式良好的一页上打印一行。 Meaning the value of one cell is the header and should be printed fat and centred, the other values should also be placed at fixed positions on the page. 表示一个单元格的值是标题,应打印在较粗且居中的位置,其他值也应放置在页面上的固定位置。

Is this with VBA possible? VBA可以吗? When I was searching for this problem I only found results for printing a worksheet or a table or parts of it, but no results to use the values of the cells and formatting them. 当我搜索此问题时,我只发现了打印工作表或表格或其一部分的结果,但没有找到使用单元格的值并对其进行格式化的结果。

Thanks in advance 提前致谢

Template is a good way to do. 模板是一个很好的方法。 With a macro there's better performance where it avoids the usage of volatile functions such as INDIRECT() However again it depends on how many volatile functions your worksheet carries. 使用宏可以避免使用诸如INDIRECT()之类的易失性函数,从而获得更好的性能。但是,这又取决于工作表中包含多少个易失性函数。

Yes, it is possible when you use the Styles in excel. 是的,当您在excel中使用样式时,这是可能的。 I know you can do Font formatting quite easily. 我知道您可以很容易地进行字体格式化。 Not sure about indenting it, but worth a try. 不确定缩进,但值得一试。

If style doesnt support it (it might in Excel 2010), you can always indent it via VBA (record a macro when you indent the values , it should look like this): 如果样式不支持它(在Excel 2010中可能支持样式),则始终可以通过VBA对其进行缩进(在缩进值时记录一个宏,它应如下所示):

Selection.InsertIndent 1

As the other answers indicate, it is certainly possible in Excel VBA, but it is not really Excel's strong point. 如其他答案所示,在Excel VBA中当然可以实现,但这并不是Excel的强项。

What would typically be done to obtain the result you seem to be after is use a fully formatted Word document with fields that are then filled in with values from an Excel worksheet. 要获得您似乎想要的结果,通常要做的是使用完全格式化的Word文档,该文档中的字段然后用Excel工作表中的值填充。 You can even cheat a bit and use the Mail Merge \\ Letter wizard to set everything up. 您甚至可以作弊一点,并使用“邮件合并\\信函”向导进行设置。

If you do want to do it all in Excel, you can find instructions and an example VBA macro here: http://www.tek-tips.com/faqs.cfm?fid=4223 如果您确实想在Excel中完成所有操作,则可以在此处找到说明和示例VBA宏: http : //www.tek-tips.com/faqs.cfm? fid =4223

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

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