Home > Software engineering >  Vc can't how to get the inside of the word vba method attribute
Vc can't how to get the inside of the word vba method attribute

Time:09-27

I need access to word document under the vc now the number of copies to print, use the word's built-in dialog box, in word test is normal, the corresponding macro code is as follows:
Sub macro (8)
'
"Acer 8
'
'
As Dim DLG Dialog
The Set DLG=Dialogs (wdDialogFilePrint)
With DLG
If the Display=1 Then
MsgBox "NumCopies=" & amp; DLG. NumCopies

End the If
End With

End Sub

Vc is to call the com interface, the question now is unable to get to the copies parameter DLG. NumCopies, query msword. TLH, inside this property is not defined, also don't know how to do now, a great god, please give directions, how to obtain the parameters, thank you!

CodePudding user response:

Fyi:
//1. Create a new console in the VC program, choose support MFC (of course, you can also choose not to support of MFC, but will be very troublesome) 
//2. Press CTRL + W v MFC ClassWizard, Add a Class - & gt; From a type library, choose your word's type library
//(for example my word2003, installed in e disk, my path is "e: \ edittools \ Microsoft office \ office11 \ msword olb"),
//choice to end, in the pop-up window, select the let classwizard generated wrapper classes, in this case need
//_Application,
//Documents,
//_Document,
//Range
//the four classes, selected after they click OK
//3. Enter your main function of the CPP file, add a header file reference
//# include "msword. H"//reference just classwizard generated idispatch wrapper class
//4. Add the code
//console_word. CPP: Defines the entry point for the console application.
//

# include "stdafx. H"
# include "console_word. H"
# include "msword. H"
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif

/////////////////////////////////////////////////////////////////////////////
//The one and only The application object

CWinApp theApp;

Int _tmain (int arg c, TCHAR * argv [], TCHAR * envp [])
{
Int nRetCode=0;

//initialize the MFC and the print and the error on failure
if (! AfxWinInit (: : GetModuleHandle (NULL), NULL, : : GetCommandLine (), 0))
{
//TODO: change the error code to suit your needs
Printf (_T (" Fatal Error: MFC initialization failed! \ n "));
NRetCode=1;
}
The else
{
//TODO: code your application 's behaviors here.
If (CoInitialize (NULL).=S_OK)
{
AfxMessageBox (" initialize COM support library failed!" );
The return - 1;
}

_Application wordApp;
The Documents docs.
_Document doc.
The Range aRange;
COleVariant vTrue (TRUE) (short), vFalse ((short) FALSE), vOpt ((long) DISP_E_PARAMNOTFOUND VT_ERROR);
Cstrings TXT.

WordApp. CreateDispatch (" Word. Application ", NULL);
WordApp. SetVisible (FALSE);
Docs=wordApp. GetDocuments ();
Doc=docs. Open (COleVariant (" c: \ \ new \ \ test. Doc "), vFalse, vTrue, vFalse, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt, vOpt);
ARange=doc. Range (vOpt vOpt);
TXT=aRange the GetText ();
AfxMessageBox (TXT);//for GetText here is plain text word file, you can write in the TXT file
Printf ("] [% s \ n ", TXT. GetBuffer (. TXT GetLength ()));//the newline instead of \ r \ n \ r, so you need to redirect output to a text file as a result,
ARange. ReleaseDispatch ();
Doc. Close (vOpt vOpt, vOpt);
Doc. ReleaseDispatch ();
Docs. ReleaseDispatch ();
WordApp. Quit (vOpt vOpt, vOpt);
WordApp. ReleaseDispatch ();

CoUninitialize ();
}

Return nRetCode;
}


CodePudding user response:

Sub PrintOut ([Background], [Append], [Range], [OutputFileName], [From], [To], [Item], [Copies], [Pages], [PageType], [PrintToFile], [Collate], [FileName], [ActivePrinterMacGX], [ManualDuplexPrint], [PrintZoomColumn], [PrintZoomRow], [PrintZoomPaperWidth], [PrintZoomPaperHeight])

CodePudding user response:

Thank you for your reply, this parameter is set to print, my request is to obtain in the print dialog before setting copies, not direct print,

refer To the second floor bjym1987 response:
Sub PrintOut ([Background], [Append], [Range], [OutputFileName], [From], [To], [Item], [Copies], [Pages], [PageType], [PrintToFile], [Collate], [FileName], [ActivePrinterMacGX], [ManualDuplexPrint], [PrintZoomColumn], [PrintZoomRow], [PrintZoomPaperWidth], [PrintZoomPaperHeight])

CodePudding user response:

reference 1st floor zhao4zhong1 response:
are for reference only:
//1. Create a new console in the VC program, choose to support the MFC (of course, you can also choose not to support of MFC, but will be very troublesome) 
//2. Press CTRL + W v MFC ClassWizard, Add a Class - & gt; From a type library, choose your word's type library
//(for example my word2003, installed in e disk, my path is "e: \ edittools \ Microsoft office \ office11 \ msword olb"),
//choice to end, in the pop-up window, select the let classwizard generated wrapper classes, in this case need
//_Application,
//Documents,
//_Document,
//Range
//the four classes, selected after they click OK
//3. Enter your main function of the CPP file, add a header file reference
//# include "msword. H"//reference just classwizard generated idispatch wrapper class
//4. Add the code
//console_word. CPP: Defines the entry point for the console application.
//

# include "stdafx. H"
# include "console_word. H"
# include "msword. H"
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif

/////////////////////////////////////////////////////////////////////////////
//The one and only The application object

CWinApp theApp;

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related