Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-10-2020, 05:12 AM
kishan patel kishan patel is offline I got error for Macro script when I used for split large file and convert as HTML Windows 10 I got error for Macro script when I used for split large file and convert as HTML Office 2019
Novice
I got error for Macro script when I used for split large file and convert as HTML
 
Join Date: Oct 2020
Posts: 2
kishan patel is on a distinguished road
Post I got error for Macro script when I used for split large file and convert as HTML

Dear all,

I have a large file around 1300 pages and wanted to split by pages and also change file formate as HTML but getting error.

My Macro script is,

Sub BreakOnPage()
' Used to set criteria for moving through the document by page.
Application.Browser.Target = wdBrowsePage

For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")

'Select and copy the text to the clipboard
ActiveDocument.Bookmarks("\page").Range.Copy

' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
' Removes the break that is copied at the end of the page, if any.
Selection.TypeBackspace
ChangeFileOpenDirectory "C:"
DocNum = DocNum + 1


ActiveDocument.SaveAs FileName:="page_" & DocNum & ".html
ActiveDocument.Close

' Move the selection to the next page in the document
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub


Aprreciated for your help.
Reply With Quote
  #2  
Old 10-10-2020, 05:36 AM
gmayor's Avatar
gmayor gmayor is offline I got error for Macro script when I used for split large file and convert as HTML Windows 10 I got error for Macro script when I used for split large file and convert as HTML Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,298
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

There are a couple of issues with your code, but the likely problem issues are that you have not defined the file type and you have not set the save path. Saving to the root of the C:\ drive would almost certainly be blocked by security issues.
It is better to declare your variables and name the documents e.g.


Code:
Sub BreakOnPage()
Dim i As Integer
Dim oSource As Document, oTarget As Document
Dim oRng As Range
Dim strPath As String
    strPath = "C:\Path\" 'enter the path here
    ' Used to set criteria for moving through the document by page.
    Application.Browser.Target = wdBrowsePage
    Set oSource = ActiveDocument
    For i = 1 To oSource.BuiltInDocumentProperties("Number of Pages")
        'Set a range to the page
        Set oRng = oSource.Bookmarks("\page").Range
        ' Remove the break that is copied at the end of the page, if any.
        oRng.End = oRng.End - 1
        'Create new document to copy the range to.
        Set oTarget = Documents.Add
        oTarget.Range.FormattedText = oRng.FormattedText
        oTarget.SaveAs FileName:=strPath & "page_" & i & ".html", FileFormat:=wdFormatFilteredHTML
        oTarget.Close
        ' Move the selection to the next page in the document
        Application.Browser.Next
    Next i
    oSource.Close savechanges:=wdDoNotSaveChanges
    Set oSource = Nothing
    Set oTarget = Nothing
    Set oRng = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-10-2020, 05:50 AM
kishan patel kishan patel is offline I got error for Macro script when I used for split large file and convert as HTML Windows 10 I got error for Macro script when I used for split large file and convert as HTML Office 2019
Novice
I got error for Macro script when I used for split large file and convert as HTML
 
Join Date: Oct 2020
Posts: 2
kishan patel is on a distinguished road
Default Again error for file type

Dear Gmayor,

Thanks for your suggestion, I did same as you told, but it showing same error.

see attached image,
Attached Images
File Type: jpg Screenshot (86).jpg (139.5 KB, 8 views)
Reply With Quote
  #4  
Old 10-10-2020, 08:36 PM
gmayor's Avatar
gmayor gmayor is offline I got error for Macro script when I used for split large file and convert as HTML Windows 10 I got error for Macro script when I used for split large file and convert as HTML Office 2016
Expert
 
Join Date: Aug 2014
Posts: 3,298
gmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to allgmayor is a name known to all
Default

Does the path (strPath) exist?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
error 5156, macro assign word, split and convert html

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
I got error for Macro script when I used for split large file and convert as HTML DOCX TO HTML - script writing adikrak Word VBA 7 01-02-2020 02:52 PM
Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error zipit189 Word VBA 7 03-18-2015 01:13 PM
Ongoing Nightmare - Opening a .txt. or .csv containing HTML script freshfrost Excel 4 09-28-2014 12:23 AM
I got error for Macro script when I used for split large file and convert as HTML Convert word files to html including hyperlink file types MikS Word 3 06-12-2012 05:39 AM
Convert a file from HTML to WORD format weblayout view gtselvam Word 0 12-02-2008 03:53 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 10:18 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft