Save doc as Webpage but cannot view in browser at the same time

  • Thread starter Michelle via OfficeKB.com
  • Start date
M

Michelle via OfficeKB.com

I am writing the following code, it will popup a save as dialog, when I got the path and name info, i run ActiveDocument.SaveAs to save doc as webpage. After that, I tried to call ActiveDocument.FollowHyperlink to open that webpage, however, nothing happen.

But then, i tried to call ActiveDocument.FollowHyperlink to open a file which is saved before, it works fine.

I feel strange that if i just saved the file, i can't immediately call ActiveDocument.FollowHyperlink to view the page. Anyone can help?

Dim Path, Name, fullPath As String

With Dialogs(wdDialogFileSaveAs)
If .Display Then
Path = WordBasic.FileNameInfo(.Name, 5)
Name = WordBasic.FileNameInfo(.Name, 4)
fullPath = Path & Name & ".html"
ActiveDocument.SaveAs FileName:=fullPath , FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=False, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False
ActiveDocument.FollowHyperlink fullPath
End If
End With
 
K

Klaus Linke

Hi Michelle,

It seems you try to open a document that already is open. So nothing happens.

If you want to see a web preview of the current doc, you could use
ActiveDocument.WebPagePreview

Regards,
Klaus
 
M

Michelle via OfficeKB.com

But I want to open a new Browser to view the page, so I don't use
WebPagePreview.
 
K

Klaus Linke

Michelle via OfficeKB.com said:
But I want to open a new Browser to view the page, so I don't
use WebPagePreview.


Hi Michelle,

The more I look at it, the less I understand why your code doesn't work...

Maybe you can use the Shell function with iexplore.exe instead of
FollowHyperlink.

It seems messy since you have to figure out the full path to the IE program
(... if I didn't miss something obvious).
And the method doesn't work with other browsers :-(

See code below...
Klaus



Dim strProgramFilesDir As String
strProgramFilesDir = System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", _
"ProgramFilesDir")
Dim strIE As String
strIE = System.PrivateProfileString("", _
"HKEY_LOCAL_MACHINE\Software\Microsoft\IE Setup\Setup", _
"Path") & _
"\iexplore.exe"
strIE = Replace(strIE, "%ProgramFiles%", strProgramFilesDir, , , vbTextCompare)
Dim strShell As String
strShell = strIE

Dim Path, Name, fullPath As String
Dim fullPath2 As String
With Dialogs(wdDialogFileSaveAs)
If .Display Then
Path = WordBasic.FileNameInfo(.Name, 5)
Name = WordBasic.FileNameInfo(.Name, 4)
fullPath = Path & Name & ".html"
ActiveDocument.SaveAs FileName:=fullPath, FileFormat:=wdFormatHTML, _
LockComments:=False, Password:="", AddToRecentFiles:=False,
WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False,
SaveAsAOCELetter:= _
False
' ActiveDocument.FollowHyperlink fullPath
strShell = strShell & " " & Chr(34) & fullPath & Chr(34)
Shell strShell, vbNormalFocus
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top