Simple VBA knowledge (1) workbook, table addition, deletion, and modification

Source: Internet
Author: User

After entering the factory, I found that the factory is completely different from the company. Most people do not need computers, let alone some management software. At most, you can use Excel to prepare various forms, which cannot be compared with various paperless office software in big companies.

Considering that the manual cost of preparing various tools and software is relatively high, the so-called fastest C # cannot compile a repository for management overnight, or decide to use Excel more in the future, in this way, all personnel can be improved to make it more efficient.

VBA has become a top priority. because the goal is to use Excel to make various reports or other things, the accumulated things are mostly related to these things, which are incomplete and practical.

Sub creates a new Workbook () set newbook = workbooks. add With newbook. title = "all sales ". subject = "sales ". saveas filename: = "allsales.xls" End withend subsub open an existing workbooks. open ("C: \ myfolder \ mybook.xls") end subsub copy a table to the current table () fname = "E: \ business accumulation \ vba_test_two.xls "'address and file name of the Excel file to be copied. Modify set D = GetObject (fname)' to open the file D. sheets ("sheet1 "). cells. copy activesheet. cells (1, 1) 'completely copies sheet1 to the current table D. close 'close the file set D = nothingend subsub to copy the table from the workbook to the B Workbook () dim A as workbook, B as workbook set a = workbooks. open ("E: \ business accumulation \ vba_test_two.xls") Set B = workbooks. open ("E: \ business accumulation \ vba_test_three.xls"). sheets ("sheet1 "). copy after: = B. sheets (B. sheets. count) B. sheets (B. sheets. count ). name = "test renaming". close B. save B. closeend sub deletes an existing Worksheet () Set B = workbooks. open ("E: \ business accumulation \ vba_test_three.xls") application. displayalerts = false B. sheets ("test renaming "). delete application. displayalerts = truenext B. save B. closeend sub

 

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.