=> Delete Table with Frontpage VBA

A

Alexander

Delete Table with Frontpage VBA
=======================

Being the focus located in a table cell, y want with Fp-VBA select the whole
Tabel and delete ist.

What is the correspondent Fp VBA Code for this?

Thanks
Alexander
 
P

Peter Aitken

Alexander said:
Delete Table with Frontpage VBA
=======================

Being the focus located in a table cell, y want with Fp-VBA select the whole
Tabel and delete ist.

What is the correspondent Fp VBA Code for this?

Thanks
Alexander

Do the steps manually while macro recording is turned on. Then the recorded
macro will contain the code you need.
 
A

Alexander

Thanks for your answer
I'm still working with Fp2000
"Record Macro" Is not available in this version

Can you give me a hint?

Thanks
Alexander
 
P

Peter Aitken

Alexander said:
Thanks for your answer
I'm still working with Fp2000
"Record Macro" Is not available in this version

Can you give me a hint?

Thanks
Alexander

Whoops - my mistake. I assumed that FP 2002 had macro recording because it
has a Macro command, but it does not. Sorry,
 
A

Alexander

Whoops - my mistake. I assumed that FP 2002 had macro recording because it
has a Macro command, but it does not. Sorry,

.... a macro recording feature would have been great ...
.... I was allready looking forward to get my upgrade ...
may be next time.
 
A

Alexander

Delete Table with Frontpage VBA
=======================

MY QUESTION WAS:
Wenn der Focus auf einer beliebigen Stellen der Tabele liegt möchte ich mit
Fp VBA Code:
1. die gesamte Tabelle aktivieren
2. die Tabele löschen>
Was ist der Fp VBA Code hierfür?


FOUND SOLUTION:

Solution was found in the CommandBars.Execute Methode and the SendKeys
Funktion
I dont like the Sendkeys funktion very much in this circumstance.

If anyone has a better solution, please tell.

Alexander

CODE:
'=================================================
Public Sub Fp_DeleteTable(Optional MyForm As Object)
'-------------------------------
'Deletes the Frontpage Table which contains the Selection

'Fp_DeleteTable
'Fp_DeleteTable Me '(If you use this Procedure in a Form)

'-------------------------------
'tested for Frontpage 2000
'-------------------------------
On Error Resume Next
Dim rng As IHTMLTxtRange
Dim Top, Left
Dim ControlType, ControlId
ControlType = 1
ControlId = 803 '(Id of the "Select Whole Table" Command)
'------------------------------
'Hide MyForm if necessary

If IsMissing(MyForm) Then
Else
Left = MyForm.Left
Top = MyForm.Top
MyForm.Hide '<<<<<<<< Focus is passed to Frontpage-Window
End If
'------------------------------
'Select whole Table

CommandBars(CommandBars.FindControl(ControlType,
ControlId).Parent.Index).FindControl(ControlType, ControlId).Execute
If Err <> 0 Then Err = 0
'------------------------------
'Delet Table
SendKeys "{DEL}", False
DoEvents
'------------------------------
'Show MyForm if necessary

If IsMissing(MyForm) Then
Else
MyForm.Show '<<<<<<<< Focus is returned to MyForm
MyForm.Top = Top
MyForm.Left = Left
End If
'-------------------------------
End Sub
'=================================================
 
M

MD Websunlimited

Hi Alexander

That is really bad form.

To delete a table, locate it in the document then set the outerHTML to an empty string.

Dim oTable As IHTMLElement

Dim oElementColl As IHTMLElementCollection

Set oElementColl = ActiveDocument.all.tags("table")

'Delete the first table found

Set oTable = oElementColl.item(0)

oTable.outerHTML = ""


Along with learning the FP OM an understanding of the DHTML OM is also required. It is obvious that time needs to be spent reading
the "FREE" materials on MSDN

BTW, this code is just a kludge an requires that robustness be added if you intend to distribute this for other to utilize, e.g, an
should be rewritten like so.

Dim oTable As IHTMLElement

Dim oElementColl As IHTMLElementCollection

if not ActiveDocument is Nothing then
Set oElementColl = ActiveDocument.all.tags("table")

'Delete the first table found

If not oTable is Nothing then
Set oTable = oElementColl.item(0)
else
' no table tags so error routine here
end if
oTable.outerHTML = ""
else
' no document so error routine here
end if

--
Mike -- FrontPage MVP '97-'02
http://www.websunlimited.com
Need to have an Ad Banner that allow individual links?
http://www.websunlimited.com/order/Product/navigation/adbanner.htm
FrontPage Add-ins Since '97 2003 / 2002 / 2000 Compatible
 
A

Alexander

Hi Mike
That is really bad form.
Im aware of this and it nust be changed

I need to delete the table which is selcted in the "NormalView"
(Reason: when I retrieve the HtmlCode of the selected Tabe with
"rng = ActiveDocument.selection.createRange" I can't paste it again
with "rng.pastHTML" because this results in an error. I have to delete
the table first)

Refering your Code:
Is it possible to identify a SELECTED teble in the TableCollection.?
I don't think so.

Thanks
Alexander
{I also will have a look at MSDN}

--------------------------


MD Websunlimited said:
Hi Alexander

That is really bad form.

To delete a table, locate it in the document then set the outerHTML to an empty string.

Dim oTable As IHTMLElement

Dim oElementColl As IHTMLElementCollection

Set oElementColl = ActiveDocument.all.tags("table")

'Delete the first table found

Set oTable = oElementColl.item(0)

oTable.outerHTML = ""


Along with learning the FP OM an understanding of the DHTML OM is also
required. It is obvious that time needs to be spent reading
the "FREE" materials on MSDN

BTW, this code is just a kludge an requires that robustness be added if
you intend to distribute this for other to utilize, e.g, an
 
A

Alexander

SOLUTION FOUND
rng = ActiveDocument.selection.createRange
rng.pastHTML ""
This code deletes the selected Table
Thanks a lot

Alexander

'-------------------------------
 
M

MD Websunlimited

Yep if the table is already selected then that works but then so does selecting the table and hitting the delete key ;>) That is why
I did not present it as having the user select the table.
 
A

Alexander

Sorry, I was a little too hasty in thinking I had found the solution.
It was my SendKeys function which deleted the Table.

If you get the Table code with rng =
ActiveDocument.selection.createRange,
then rng.pastHTML "" (wether the argument is "" or "xyz"),
always will result in an error.

At the moment, the SendKeys method seem to be the only way to
delete in an automated way a table selected with the cursor.

Thanks anyway
Alexander

MD Websunlimited said:
Yep if the table is already selected then that works but then so does
selecting the table and hitting the delete key ;>) That is why
 
M

MD Websunlimited

No no no.

You need to do some reading about the FP OM and how to work with it. Invest the time and it will be well worth the effort.
 
P

Peter Aitken

MD Websunlimited said:
No no no.

You need to do some reading about the FP OM and how to work with it.
Invest the time and it will be well worth the effort.
Mike's right. Programming FP is complicated - there's no getting around it.
You will have to invest a lot of time and effort to learn at least the
basics. You cannot expect to ask questions here and get all the answers.
Even if they work you will not understand why and are likely to get into a
lot of trouble.
 
A

Alexander

Get hand of a table with "myDocument.all.tags("TABLE").Item(?)"
and delete ist this way is easy. But the Problem is in the "?"

How can I detect the table which is selected with the cursor
in the ActivePageWindow ?
As the table was created with Frontpage it hasn't got an ID

I WANT TO SELECT A TABLE WITH THE CURSOR,
READ ITS CODE INTO A TEXTBOX.
EDIT THE HTML TEXT THERE BY HAND, AND PASS
THE RESULT BACK TO FRONTPAGE.

I get the code of the table with
"RNG = ActiveDocument.selection.createRange"
and pass it back with "RNG.pastHTML".

But I need to delete the original and still selcted Table first
befor I execute the "RNG.pastHTML" command because
if not an error will be the result.

How can I get hold of the cursor selcted Tabel.
I don't know where to start reading.
Does there exist something like:
"myDocument.all.tags("TABLE").Status(vbSelected)" ????

Thanks
Alexander



MD Websunlimited said:
No no no.

You need to do some reading about the FP OM and how to work with it.
Invest the time and it will be well worth the effort.
 

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