[Reprinted] use the Excel macro recording function to view the operation code in InterOP. Excel.

Source: Internet
Author: User

In many projects, we use the Excel export function. Usually InterOP. Excel DLL is used.
If you use an Object Browser to view it, you will see a lot of object attribute methods, but these are not instructions, and rarely understand what it means literally, especially for people with poor English. What's more inconvenient is that there are many attribute methods under an object, but you areCodeWhen you press "." In, the smart prompt will not show the method attribute list, but there will be only one GetType (). depressed.
My project users have many requirements on the generated Excel files, such as the background color of some cells and the formula of some cells, when Excel is expected to scroll down the scroll bar below, the first three columns will always be fixed. You may do this in Excel software, but you do not know which attribute can be set in the Code and which method can implement this function. What should you do at this time? One of my friends told me this method. I will share it today.
The Excel menu contains a macro recording function that records the VB code running in Excel during your operations.
Tools --> macro --> record new macro
A small form is displayed.

Click OK and a stop button appears,
After the operation is complete, click STOP.
Next, you will do what you want to achieve. For example, if the first three columns are fixed, you can select column D and choose menu window --> freeze panes.
In this way, the operation is complete and click STOP.

Then let's look at the recorded VB code. Menu tools --> macro --> macros...
Select edit or choose tools> macro> Visual Basic Editor.

After opening, we can see the code for each step we just recorded.

Sub macro3 ()
'
'Macro3 macro
'Macro recorded 2006-6-23 by Administrator

Columns ("D: D"). Select
Activewindow. freezepanes= True

End sub
The original code isActivewindow. freezepanesThis item is under control.
Finally, you can write it like this in the code.
Excelsheet. cells (1, 3). Select ()
Excelapp.Activewindow. freezepanes= True

 

This completes. The same is true for other effects, such as setting formats, formulas, colors, and styles.

Excelsheet. Range (ES. cells (4, 4), es. cells (4, 7). Interior. colorindex = 44

How about it? I hope it will help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.