简体   繁体   English

从VB6在Excel中格式化

[英]formatting in Excel from VB6

我正在使用Excel Automation创建一个Excel工作表并向其中写入数据。.我想知道如何仅使特定单元格变为BOLD,以及如何使单元格大小自动适应其内容。.pls帮助

There is an easy way to find out, how to do things in Excel using code: macro recording. 有一种简单的方法可以找到如何使用代码在Excel中执行操作:宏录制。

Since Excel provides his API through COM-interfaces, VBA, VB scripts and programs written on other languages - are very similiar. 由于Excel通过COM接口提供了他的API,所以VBA,VB脚本和用其他语言编写的程序非常相似。 So, run macro recording, do the things you want to automate, open recorded macro for edit and look at the code. 因此,运行宏录制,执行您想自动化的事情,打开录制的宏进行编辑并查看代码。

In your case it will look like this one: 在您的情况下,它将如下所示:

Range("B2").Select                      -- particular cell selection
ActiveCell.FormulaR1C1 = "123"          -- cell text fill
Selection.Font.Bold = True              -- enabled bold cell style
Columns("B:B").EntireColumn.AutoFit     -- autofitted column

That's VBA code. 那是VBA代码。 VB6 will be almost the same, except one thing: you should do this commands with the Excel.Worksheet object. VB6几乎相同,除了一件事:您应该使用Excel.Worksheet对象执行此命令。 Please refer tutorials like this one: http://www.vbforums.com/showthread.php?t=391665 - to find out more. 请参考这样的教程: http : //www.vbforums.com/showthread.php?t= 391665-了解更多信息。

Good luck! 祝好运!

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

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