Office Programming Ideas (VBA)

Source: Internet
Author: User
Tags range
Programming below is VB to open the file code:

If Dir ("D:\excel.bz") = "Then" Determines whether Excel is open
Set xlapp = CreateObject ("Excel.Application") ' Create Excel application class
xlapp.visible = True ' Set Excel visible
Set xlbook = XlApp.Workbooks.Open ("D:\test.xls") Open Excel workbook
Set xlsheet = xlbook.worksheets (1) ' Opens Excel worksheet





Activeworkbook.save

Xlapp.displayalerts = False
xlapp.screenupdating = True
xlApp.Quit


End If

Then open the Excel worksheet, do what the program is doing on the worksheet and record it as a "macro," and copy it directly to the blank space above. It's done.
The macro code is as follows (VBA code, where a small number of the code is modified in the programming syntax of VBA):

' The following information comes from macros
Range ("A4:c4"). Select
Selection.Copy
Range ("A11"). Select
Activesheet.paste
Range ("A3:c3"). Select
Application.cutcopymode = False
Selection.Copy
Range ("A4"). Select
Activesheet.paste
Range ("A5"). Select
Activesheet.paste
Range ("A6"). Select
Activesheet.paste
Range ("A7"). Select
Activesheet.paste
Range ("A8"). Select
Activesheet.paste
Range ("A9"). Select
Activesheet.paste
Range ("A10"). Select
Activesheet.paste


Application.cutcopymode = False
For i = 1 to 9
Range ("A" & (i + 1)). Select
ACTIVECELL.FORMULAR1C1 = "Project" & I
Range ("B" & (i + 1)). Select
ACTIVECELL.FORMULAR1C1 = i
Range ("C" & (i + 1)). Select
ACTIVECELL.FORMULAR1C1 = "description" & I
Next

Range ("B11"). Select
ACTIVECELL.FORMULAR1C1 = "=sum (r[-9]c:r[-1]c)"


Similar to the operation of Word, other languages (such as C + +) can do COM programming according to this syntax structure





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.