Cara simpan tiap halaman file word sebagai sebuah file html terpisah secara otomatis – Script macro Microsoft Word

Misalnya kita punya sebuah file word ratusan halaman, lalu kita ingin menconvert tiap halaman file tersebut sebagai satu file html terpisah, kita bisa menggunakan script macro di bawah ini:

Sub SaveAsHtmls()
'
' SaveAsHtmls Macro
'
'

    Dim orig As Document
    Dim page As Document
    Dim numPages As Integer
    Dim idx As Integer
    Dim fn As String
    
       
    ' Keep a reference to the current document.
    Set orig = ActiveDocument
    
    ' Calculate the number of pages
    numPages = ActiveDocument.BuiltInDocumentProperties("Number of Pages")
    
    For idx = 1 To numPages
        ' Make sure the document is active
        orig.Activate
               
        ' Go to the page with index idx
        Selection.GoTo What:=wdGoToPage, Name:=idx
    
        ' Select the current page
        Selection.GoTo What:=wdGoToBookmark, Name:="\page"
               
        ' Copy the selection
        Selection.Copy
        
        ' Create a new document
        Set page = Documents.Add
        
        ' Activate it
        page.Activate
               
        ' Paste the selection
        Selection.Paste
        
        ' Generate the file name
        fn = "C:\converted\page_" + CStr(idx) + ".html"
        
        ' Save the document as HTML
        page.SaveAs FileName:=fn, FileFormat:=wdFormatHTML, AddToRecentFiles:=False
        
        ' Close the document
        page.Close
        
    Next

End Sub

Cara menggunakan script di atas akan Om Puter tunjukin di video di bawah ini:

loading...

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *