UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Open Html Files For Formating With Ms Word By Using Vba, Access 2003    
 
   
Pleasure
post Mar 27 2020, 10:21 AM
Post#1



Posts: 269
Joined: 1-July 05
From: Greece


Hello Folks.

Wish you all health and hapyness.
Be safe and protect yourselves and all the others until this "corona" thing passes by.
I kindly ask you if there is a way to open with late binding one html file, not for formated viewing but for editing the html code. So the Ms Word should show as the code, not the result of the code.

eg, this is good code snip (from DEVelopers HUT with minor changes):
How should we change it to open the html file for viewing the code:

CODE
Sub LaunchWord()
Dim objApp As Object
Dim Doc As Object

    'See if Word is already running
    On Error Resume Next
    Set objApp = GetObject(, "Word.Application")

    If Err.Number <> 0 Then
        'Launch a new instance of Word
        Err.Clear
        On Error GoTo Error_Handler
        Set objApp = CreateObject("Word.Application")
        Set Doc = objApp.Documents.Open("c:\temp\1234.html")
        objApp.Visible = True 'Make the application visible to the user (if wanted)
    End If

Exit Sub

Error_Handler:
    MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf & "Error Number: " & _
    Err.Number & vbCrLf & "Error Source: LaunchWord" & vbCrLf & "Error Description: " & _
    Err.Description, vbCritical, "An Error has Occurred!"
    Exit Sub



Thank you !!!


--------------------
Dum spiro spero ...
Go to the top of the page
 
theDBguy
post Mar 27 2020, 10:54 AM
Post#2


UA Moderator
Posts: 78,125
Joined: 19-June 07
From: SunnySandyEggo


How do you do it manually in Word? Typically, you would use Word to create a web page because you don't want to use code tags. Otherwise, you would use a different HTML editor.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
MadPiet
post Mar 27 2020, 12:20 PM
Post#3



Posts: 3,710
Joined: 27-February 09



"for editing the HTML code"... You can use almost any text editor to modify HTML code, since it's essentially plain text. if someone has already done all the formatting, you just need to replace the text between the tags. but if you don't understand HTML/CSS, it could be a challenge.
Go to the top of the page
 
Pleasure
post Mar 28 2020, 07:34 AM
Post#4



Posts: 269
Joined: 1-July 05
From: Greece


Thanks for the reply.
I actually want to open the web page as text with winword in order to initiate word automation for search and replace of some values in the that html code.
I am not able to do it with common menus through word (meaning not able to open an html page as text without formating). So I thought that there is a solution through vba

--------------------
Dum spiro spero ...
Go to the top of the page
 
DanielPineault
post Mar 28 2020, 08:07 AM
Post#5


UtterAccess VIP
Posts: 7,344
Joined: 30-June 11



Why not simply read the html file into a VBA string variable and then use Replace() as required and then write the VBA variable back to the html file.

https://www.devhut.net/2012/05/14/vba-read-file-into-memory/
https://www.devhut.net/2012/07/07/vba-export-to-text-file/

As a side note, Word is a horrible HTML editor! It garbles and messes HTML add so much [censored] CSS, ... Just stay away at all cost.

Also, "there is no way to view the source code of an HTML document in the most recent versions of Microsoft Word." -- taken from https://www.computerhope.com/issues/ch001634.htm

--------------------
Daniel Pineault (2010-2019 Microsoft MVP, UA VIP, EE Distinguished Expert 2018)
Professional Help: https://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: https://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
ADezii
post Mar 28 2020, 09:35 AM
Post#6



Posts: 2,996
Joined: 4-February 07
From: USA, Florida, Delray Beach


  1. First and foremost, wishing you health and happiness also!
  2. Why not use Low Level Input/Output Functions to:
    1. Open the File.
    2. Replace specific Text Strings with new Strings.
    3. Output the Revised File with all changes made.
  3. The following Code segment will:
    1. Open the 1234.htm File in the C:\Test\ Folder.
    2. Change any occurrences of the Color Code #ffcc99 to #000080.
    3. Write the Revisions to a New File,, in this case C:\Test\1234_Revised.htm.
  4. Code Definition:
    CODE
    Dim strLine As String

    Open "C:\Test\1234.htm" For Input As #1
    Open "C:\Test\1234_Revised.htm" For Output As #2

    Do While Not EOF(1)
      Line Input #1, strLine
        If InStr(strLine, "#ffcc99") > 0 Then
          strLine = Replace(strLine, "#ffcc99", "#000088")
        End If
        Print #2, strLine
    Loop

    Close #1
    Close #2
  5. I have only tested the Code minimally, but it does appear to work quite well.

This post has been edited by ADezii: Mar 28 2020, 09:48 AM
Go to the top of the page
 
Pleasure
post Apr 1 2020, 11:04 AM
Post#7



Posts: 269
Joined: 1-July 05
From: Greece


Hello
Sorry for the delay and thanks everybody for the reply.
Unfortunately there is a huge issue with UTF-8 and Greek Characters.
The source html code contains Greek Characters and the page is encoded to UTF-8
When using the replace function, there is an issue with the encoding, giving up as a result some unrecognisable characters.
When using the replace job inside ms word, I do not have this problem. So I can do it easily with word automation but I do not know how to open a html file to show the code instead of the html formating ...

--------------------
Dum spiro spero ...
Go to the top of the page
 
ADezii
post Apr 1 2020, 12:41 PM
Post#8



Posts: 2,996
Joined: 4-February 07
From: USA, Florida, Delray Beach


QUOTE
I do not know how to open a html file to show the code instead of the html formating ...

  1. The following Code using Automation will:
    1. Open the File 1234.html in the C:\Test\ Folder.
    2. 1234.html will be opened in Edit Mode (ReadOnly=False).
    3. The File will be Opened as Plain Text (wdOpenFormatText).
    4. The Document Window will be Visible (Visible:=True) as well as the Main Word Window (appWord.Visible = True).
  2. Code Definition (Partial):
    CODE
    Dim appWord As Word.Application
    Dim doc As Word.Document

    Set appWord = New Word.Application
        appWord.Visible = True
        
    Set doc = appWord.Documents.Open(FileName:="C:\Test\1234.html", ReadOnly:=False, _
                                     Format:=wdOpenFormatText, Visible:=True)
  3. The use of Early Binding was invaluable in this case. If you are using Late Binding, then you cannot use the Intrinsic Constant (wdOpenFormatText), instead you must use the Literal Value of 4, as in:
    CODE
    doc.Format = 4

This post has been edited by ADezii: Apr 1 2020, 12:43 PM
Go to the top of the page
 
Pleasure
post Apr 1 2020, 02:21 PM
Post#9



Posts: 269
Joined: 1-July 05
From: Greece


RESPECT !!!
Thanks a lot
Moving right away to test it

--------------------
Dum spiro spero ...
Go to the top of the page
 
Pleasure
post Apr 1 2020, 02:46 PM
Post#10



Posts: 269
Joined: 1-July 05
From: Greece


Works Perfectly.
Thank you

uarulez2.gif

--------------------
Dum spiro spero ...
Go to the top of the page
 
ADezii
post Apr 1 2020, 02:53 PM
Post#11



Posts: 2,996
Joined: 4-February 07
From: USA, Florida, Delray Beach


yw.gif , Good Luck with your Project.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    31st May 2020 - 11:33 AM