I. Introduction to Theory
The "macro" is only for the Office.
MACRO: a command that can automatically execute an operation is collectively referred to.
VBA: Visual Basic for application. It is a macro language used in office, mainly to enhance the automation capability of software such as Word and Excel. The syntax of VBA is similar to that of VB, but it provides many functions and objects not available in VB. These functions and objects are for office applications.
2. Use Macros in office
Macro application in office (word)
Tools-macros-recording new macros
Then perform an operation. For example, check an image and then "Stop macro recording"
Tool-macro-Macro... -- View
Macro code: Sub macro1 ()
Macro1 macro
'Macro in 2004-11-26 Recorded by user 46'
Selection. inlineshapes. addpicture filename: = _
"C: \ Documents and Settings \ Administrator \ Desktop \ 2003121512223104481.bmp", linktofile: = false, savewithdocument: = true
End sub
Code
The above only introduces the simplest usage of macros. The macro can also operate on the toolbar. The cainiao itself is just a little simple.
Iii. Requirements for using macros in. Net (system and web. config)
If you want to operate the word COM component normally, you must grant sufficient permissions to the user. The following are my questions and questions, and I found them on the Internet. If this is not the case, you should not be able to operate the word, and an exception will occur.
1.run dcomcnfg.exe
2. Component Service-computer-my computer-DCOM configuration-find the Microsoft Word Document
3. Click Properties
4. Select "security"
5. Select "use custom Access Permissions" and "use custom launch permissions"
6. Edit permissions and add ASPnet, vs developers, and debugger user respectively.
7. Select "ID" and select "Interactive User ".
8. Add <identity impersonate = "true"/> to Web. config.
4. An example of using macros in. net
First introduce microsft word 11.0 Object Library
Private void button2_click (Object sender, system. eventargs E)
{
Object filename = @ "C: \ Inetpub \ wwwroot \ testwebapp \ test.doc"; // file name
Word. Application A = new word. applicationclass (); // create a word Program
Object nothing = system. reflection. Missing. value; // null
Word. document B =. documents. open (ref filename, ref nothing, ref nothing, ref nothing, ref nothing); // create a Word Document Object
// In fact, this macro is executed in this step.
A. selection. inlineshapes. addpicture (@ "C: \ Documents and Settings \ Administrator \ Desktop \ 2003121512223104481.jpg", ref nothing );
// Selection. inlineshapes. addpicture filename: = "C: \ Documents ents and Settings \ Administrator \ Desktop \ 2003121512223104481.bmp", linktofile: = false, savewithdocument: = true end sub B. save (); // save
B. Close (ref nothing, ref nothing, ref nothing); // close the Word Document
A. Quit (ref nothing, ref nothing, ref nothing); // exit the word Program
}
OK ~~~~~~ Check whether an image is added to the Word file ~!!
[Note] My operating environment is Windows 2003 + Word 2003 + vs. net2003