dcsimg
Results 1 to 9 of 9

Thread: Create RTF signature from HTML signature (Outlook)

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Create RTF signature from HTML signature (Outlook)

    I've created a script that will create a signature for Outlook. The first part of the script creates the TXT version of the Signature. The 2nd part creates the HTML part and the last part is supposed to create the RTF part. All parts appear to work correctly, however the RTF signature is a garbled mess.

    If I open the .RTF that is created by the script it looks perfect, but when used as the signature, yep, a garbled mess. However, if I open Word, then open the HTM file and save it as RTF, it then works fine. Huh?

    Here is the code. Essentially, I'm opening up an already created Spinneybeck.htm file and then simply saving that file as HTM. An interesting point is that when the script saves the Spinneybeck.RTF file, that file is 13KB in size. But if I manually open the HTM file in Word, and then do a save as Rich Text, the file is 45KB. Anybody have any thoughts on how to fix this?

    Code:
    		' This section builds the RTF file version
    		'==========================================================================
    		Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    		Set objFile = objFSO.CreateTextFile(RTFFileString)
    		objFile.Close
    		Set objFile = objFSO.OpenTextFile(RTFFileString, 2)  
    		objFile.Close
    		
    		Set oWord = CreateObject("Word.Application")
    		oWord.Visible = False
    		Set fso = CreateObject("Scripting.FileSystemObject")
    		If fso.FileExists("C:\Users" & LogonID & ".spinneybeck" & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.htm") then
    			fn = "C:\Users" & LogonID & ".spinneybeck" & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.htm"
    			rtffn = "C:\Users" & LogonID & ".spinneybeck" & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.rtf"
    		ElseIf fso.FileExists("C:\Users" & LogonID & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.htm") then
    			fn = "C:\Users" & LogonID & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.htm"
    			rtffn = "C:\Users" & LogonID & "\AppData\Roaming\Microsoft\Signatures\Spinneybeck.rtf"
    		End If
    		Set oDoc = oWord.Documents.Open(fn)
    		oDoc.SaveAs rtffn, wdFormatRTF
    		oWord.Quit		
    		Set oWord = Nothing

  2. #2
    PowerPoster
    Join Date
    Feb 2006
    Posts
    19,765

    Re: Create RTF signature from HTML signature (Outlook)

    What kind of "signatures" are we talking about here?

    The file location seems very, very strange. If this is someplace you have saved a file you are doing something very wrong. In any case even if some Microsoft software saved the file there, this isn't a location meant for users to twiddle with.


    All of this code looks like VBScript that is automating Office applications and such. Is there a VB question here? I don't see any.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Re: Create RTF signature from HTML signature (Outlook)

    When you create a signature in Outlook, this is the folder where those signatures are stored. Typically, one in HTML, one in RTF, and one in plain text. I am using a script to create the signatures but the RTF one is a garbled mess when Outlook attempts to use it. If I open up the RTF file in Word it looks fine, but does not look fine was Outlook uses it as a signature. The HTML and plain text files work perfectly.

    When I open the HTML file in Word and then save it as rich text it works perfectly as an Outlook signature, however, when I use the VB code to, what I think should be the same thing, open the HTML file in Word and then save it in RTF, the Signature file that Outlook opens is a garbled mess. It is also saved as a much smaller file then when I manually do it in Word.

    I guess my VB question is why is this happening? Why doesn't the automation save the file in the same format and size that doing it manually would? And, is there another way to do it so that it does?

  4. #4
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    648

    Re: Create RTF signature from HTML signature (Outlook)

    Please clarify if this is this a Visual Basic 6.0 project or VBA/VBScript code. This isn't the proper forum if this is VBA or VBScript code.

    Your question seems to be, why does Word produce inconsistent results when converting an html file to rtf using two different methods. I guess at best, your question is potentially VB related if you are asking if your code is the correct way to automate the process of saving html as rtf using Word via VB code.

  5. #5
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    648

    Re: Create RTF signature from HTML signature (Outlook)

    For the record, I can reproduce the fact that:

    1. After opening an .html file in Word and saving it as an .rtf file
    and
    2. After running your code against the same .html file and producing an rtf file

    the files produced in steps 1 and 2 differ drastically in file size and content, although both appear "correct" when opening in Word. When opening the file produced in step 1 in Notepad, I see the raw RTF stuff all as plain text. When opening the file produced in step 2 in Notepad, I see what appears to be a file that has been saved as a Word document .doc file. As a test, I repeated step 1 above but this time chose to manually save the .html file as a Word document, and the resulting file from this is almost exactly the same as automated saved "rtf" file from step 2.

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,312

    Re: Create RTF signature from HTML signature (Outlook)

    VB and VBScript look quite similar, but they really are not, which is why folks are asking about the actual language used. A VB6 answer to a VBScript question may not be correct. A VB6 answer to a VBA question is probably going to be just fine. Therefore, I'll move the thread to whichever forum seems most suitable, but at this point, I'm not sure which forum that would be.
    My usual boring signature: Nothing

  7. #7
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    648

    Re: Create RTF signature from HTML signature (Outlook)

    I was able to get this working in my testing by simply replacing wdFormatRTF with the number 6.

    Code:
    oDoc.SaveAs rtffn, 6
    wdFormatRTF is documented to be equal to 6. For me, wdFormatRTF is equal to 0, which I take to mean something more needs to be done in order to properly access these constants that Word uses. And since it equals 0, the SaveAs was saving it as a Word Document, since that is what it saves as when you pass 0 for the second parameter.

    Edit to add: My testing was done using just a .vbs file and running via Wscript.
    Last edited by OptionBase1; Mar 14th, 2019 at 04:06 PM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Mar 2019
    Posts
    3

    Re: Create RTF signature from HTML signature (Outlook)

    Thank you OptionBase1 - Your fix worked for me. I changed the code replacing

    Code:
    oDoc.SaveAs rtffn, wdFormatRTF
    with

    Code:
    oDoc.SaveAs rtffn, 6
    And for the record, this is actually VBScript.

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    33,312

    Re: Create RTF signature from HTML signature (Outlook)

    Moved to VBScript after clarification.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width