Simple search replace code - Permission Denied Error

A

Alan

Hi All,

I am trying to write a fairly simple search and replace piece of code
that I will expand later to do multiple search / replaces, but I
cannot get it to work on just one even!

The code is below, and it gives a 'Permission Denied' error (70) on
the final line before the 'End Sub'.

The active document is a single HTML document, saved on my hard disk.
I can do a search / replace / save manually no problem so I don't
think it is a file permissions issue in Windows.

Any help is much appreciated - I am a newbie with FP VBA so please be
gentle!

Alan.


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


Sub Test()

Dim objPage As DispFPHTMLDocument

Dim strFind As String
Dim strReplace As String
Dim strTest As String

Set objPage = ActiveDocument

strFind = "/abc.nsf"
strReplace = "http://www.mydomain.com/abc.nsf"

strTest = Replace(objPage.DocumentHTML, strFind, strReplace)

' This next line errors with permission denied,
' yet the HTML file is on my HDD

objPage.DocumentHTML = strTest

End Sub
 
S

Steve Easton

I have to ask: Why not just use the global replace feature of FrontPage, as it will do
exactly what you're trying to do if you tell it to search html??
 
J

Jim Cheshire \(JIMCO\)

Alan said:
Hi All,

I am trying to write a fairly simple search and replace piece of code
that I will expand later to do multiple search / replaces, but I
cannot get it to work on just one even!

The code is below, and it gives a 'Permission Denied' error (70) on
the final line before the 'End Sub'.

The active document is a single HTML document, saved on my hard disk.
I can do a search / replace / save manually no problem so I don't
think it is a file permissions issue in Windows.

Are you in Design/Normal view when this code runs? You need to be. I would
add some code in there to switch into Design/Normal view before you set the
DocumentHTML property.

--
Jim Cheshire
JIMCO
http://www.jimcoaddins.com

Check out Spam Spoiler, our new add-in!
Add e-mail links to your Web site again
without fear of spammers!
 
J

Jim Cheshire \(JIMCO\)

Steve said:
I have to ask: Why not just use the global replace feature of
FrontPage, as it will do exactly what you're trying to do if you tell
it to search html??

That's no fun! Besides what do you learn that way? ;)

--
Jim Cheshire
JIMCO
http://www.jimcoaddins.com

Check out Spam Spoiler, our new add-in!
Add e-mail links to your Web site again
without fear of spammers!
 
A

Alan

Steve Easton said:
I have to ask: Why not just use the global replace feature of
FrontPage, as it will do exactly what you're trying to do if you tell
it to search html??

Hi Steve,

The files are not all in one web, so I (thought?) I could not use the
gloabl S&R functionality - but perhaps I can....??

Thanks,

Alan.
 
A

Alan

Jim Cheshire (JIMCO) said:
Are you in Design/Normal view when this code runs? You need to be. I would
add some code in there to switch into Design/Normal view before you set the
DocumentHTML property.

Doh! Doh! Doh!

Thanks Jim - much appreciated.

I am much more an [WHISPER] excel vba programmer [/WHISPER].

FP is somewhat different I am finding, but I suspect that my general
understanding of VBA will improve from the broader knowledge.

Thanks again,

Alan.
 
S

Steve Easton

You are correct in that the global replace will only work in one web at a time. Also the web "must"
be opened in FrontPage.

That said, and looking at your code example, I "think" you are going to run into permissions issues
because your code doesn't open the web via FrontPage. Therefore you will not have "write"
permissions on the files.

( Note I said: "I think" )


--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
A

Alan

Steve Easton said:
You are correct in that the global replace will only work in one web
at a time. Also the web "must" be opened in FrontPage.

That said, and looking at your code example, I "think" you are going
to run into permissions issues because your code doesn't open the
web via FrontPage. Therefore you will not have "write" permissions
on the files.

( Note I said: "I think" )

Noted!

I will give it a go and post back here if I get stuck again.

Thanks for your assistance,

Alan.
 
J

Jim Cheshire \(JIMCO\)

Steve said:
You are correct in that the global replace will only work in one web
at a time. Also the web "must" be opened in FrontPage.

That said, and looking at your code example, I "think" you are going
to run into permissions issues because your code doesn't open the web
via FrontPage. Therefore you will not have "write" permissions on
the files.

( Note I said: "I think" )

The code he posted is VBA code which dictates that the file is open in
FrontPage. As far as permissions are concerned, Windows permissions will be
the same whether he opens the page with FrontPage or Notepad.

The issue that Alan was having was caused by trying to programmatically
manipulate a page while in Code/HTML view. The FrontPage object model does
not allow that.

--
Jim Cheshire
JIMCO
http://www.jimcoaddins.com

Check out Spam Spoiler, our new add-in!
Add e-mail links to your Web site again
without fear of spammers!
 
S

Steve Easton

Ok. "I think" I understand, but...

He referenced an http://www.domainname.com url which made me "assume" the objective is to find and
replace html in a page on a remote server. Hence my question about the permissions issue.

Did I misunderstand or overlook something??



--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer
 
J

Jim Cheshire \(JIMCO\)

Steve said:
Ok. "I think" I understand, but...

He referenced an http://www.domainname.com url which made me "assume"
the objective is to find and replace html in a page on a remote
server. Hence my question about the permissions issue.

Did I misunderstand or overlook something??

I think so. What he is doing is replacing a link that says /abc.htm with
the absolute URL. That doesn't mean that he is necessarily saving a page to
a remote URL. It's also the case that opening a file on a FrontPage
extended site is always going to open the site itself, so if you have
permission to author the site, you can save changes. :)

--
Jim Cheshire
JIMCO
http://www.jimcoaddins.com

Check out Spam Spoiler, our new add-in!
Add e-mail links to your Web site again
without fear of spammers!
 
A

Alan

I think so. What he is doing is replacing a link that says /abc.htm
with the absolute URL. That doesn't mean that he is necessarily
saving a page to a remote URL. It's also the case that opening a
file on a FrontPage extended site is always going to open the site
itself, so if you have permission to author the site, you can save
changes. :)

Guys - your conversation is seriously over my head, but this last part
is correct - I was opening and re-saving the HTML file on my local
HDD, not on a remote server (although the original file was saved to
my HDD from a remote server).

Thank you again for all your assistance - I am learning bucketloads
here so I will probaby soon be up from 'totally ignorant' to 'mildly
dangerous' in terms of my knowledge!

Regards,

Alan.
 

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