Count Number of Pages for word(.docx) document

I just want to count number of pages of MS-word(.docx) document.
We have an activity to count number of pages for PDF,

How can we do it for MS-word document?

Thank-you,
Poojan Shah

1 Like

Check this out

Cheers @poojan.shah1

  • Word Statistics - Obtain WordCount, Total Pages,Total Lines,Total Characters,Total CharactersWithSpaces and Total Paragraphs.

Hi @poojan.shah1 ,
You can try VBA

regards,

I don’t want to use external library.

Hi @poojan.shah1 ,

Could you maybe try to use the below Code in Invoke Code activity and check :

try 
{
	var wordApplication = new Microsoft.Office.Interop.Word.Application() { Visible = false };

	var myDocument = wordApplication.Documents.Open(in_FilePath);
	
	out_PageCount = myDocument.ComputeStatistics(Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages, Type.Missing);
	wordApplication.Quit();
	
}
catch( Exception e)
{
	Console.WriteLine(e.Source.ToString()+" "+e.Message.ToString()+" "+e.TargetSite.ToString());
}

Invoke Code Language is set to CSharp :

1 Like

Hi,

How do I log the “out_PageCount” argument it is not accessible

@poojan.shah1 ,

Apologies, I had to also share the Arguments Panel.

The out_PageCount is an argument passed to the Invoke Code activity, It is to be assigned with an Integer Variable so that we can get the value outside of Invoke Code.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.