#1
|
|||
|
|||
Page Count
Hi,
I want to extract a page no.'s of documents in a folder. In a Excel Column A is File name & Column B is Page No.'s While running a macro file names in a folder should get copied into Column A and then corresponding page no's get pasted in column B. I dont know whether it is possible through VBA or not, if it does not seems realistic please excuse. I tried with RegExp.Pattern = "/Type\s*/Page[^s]" , its not working. its working only with PDF formats. Format : ".docx" & ".rtf" & ".pdf" Folder selection by browse option. Strpath = Input("Please enter files pat") Your Help is highly appreciated ... Last edited by ranjan; 05-16-2022 at 12:36 PM. Reason: Added PDF |
#2
|
|||
|
|||
try the below
Quote:
|
#3
|
|||
|
|||
I want to extract a page no.'s of documents in a folder.
In a Excel Column A is File name & Column B is Page No.'s While running a macro file names in a folder should get copied into Column A and then corresponding page no's get pasted in column B. This is my requirement, I dont know how the above code will get works... Please review and do the needful.. |
#4
|
|||
|
|||
Hi,
I tried the below one but getting error, please someone can fix the issue. Code:
Sub ExtractFileNamesAndPageNumbers() Dim Path As String Dim fileNames() As String Dim FileCount As Integer Dim FileIndex As Integer Dim PageNumber As String ' Get folder path from user Path = InputBox("Enter Files Path") Path = Path & "\" ' Check if path exists If Dir(Path, vbDirectory) = "" Then MsgBox "Invalid folder path. Please try again.", vbExclamation Exit Sub End If ' Get all file names in the folder FileCount = 0 ReDim fileNames(1 To 1) If Right$(Path, 1) <> "\" Then Path = Path & "\" Filename = Dir$(Path & "*.*", vbNormal) Do Until Filename = "" If (GetAttr(Path + Filename) And vbDirectory) = vbNormal Or (GetAttr(Path + Filename) And vbHidden) = vbHidden Or (GetAttr(Path + Filename) And vbSystem) = vbSystem Then FileCount = FileCount + 1 ReDim Preserve fileNames(1 To FileCount) fileNames(FileCount) = Filename End If Filename = Dir$ Loop ' Set up Excel sheet Dim ws As Worksheet Set ws = ThisWorkbook.Sheets.Add ' Add headers ws.Cells(1, 1).Value = "File Name" ws.Cells(1, 2).Value = "Page Number" ' Loop through file names and extract page numbers For FileIndex = 1 To FileCount ' Extract page number from file name PageNumber = Mid(fileNames(FileIndex), InStrRev(fileNames(FileIndex), ".") + 1) ' Copy file name and page number to Excel sheet ws.Cells(FileIndex + 1, 1).Value = fileNames(FileIndex) ws.Cells(FileIndex + 1, 2).Value = PageNumber Next FileIndex ' Autofit columns ws.Columns.AutoFit MsgBox "File names and their page numbers have been extracted successfully.", vbInformation End Sub |
Tags |
page count |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Showing page numer and total page count in TOC | Ulodesk | Word | 5 | 02-12-2014 01:03 PM |
page count increases on its own -inserts white pages | itsema | Word | 1 | 03-06-2013 12:48 PM |
Page Count Increasing Exponentially | BobF | Word | 3 | 03-23-2012 12:20 PM |
Word: count total page of each section | salmonrose | Word | 1 | 10-15-2011 05:10 AM |
Mac Word problem - page count hover | Peophin | Word | 0 | 12-18-2009 01:02 AM |