ShaneBrennan
Programmer
Hi Everyone - hope you all had a very jolly New Year.
I am application that uses the clipboard to copy and paste tables in Word. Which works fine - but once you use any other application and do Ctrl-C the clipboard gets overwritten and the application crashes.
Basically its a catalog system, where I ahve a template with a large A4 table, which I copy, fill in the details. If there is another record to write, I paste the table to get another blank form, fill it in, and so on.
Using the .copy and .paste is easy!
I've managed to come up with the following code where I can highlight a range and past it to another range - fully formatted. But with 1 problem - it's copying a fully completed table instead a blank one! Because it's copying what's in that range at that moment in time (I've cut the code down a little :
Private Sub Form_Load()
Dim filename As String
Dim SaveFilename As String
Dim TheSourceRange As Word.Range, TheDestinationRange As Word.Range
Set oApp = CreateObject("Word.Application")
With oApp
filename = "c:\temp\Catalogue Template.doc"
SaveFilename = "c:\Temp\Finished Report.doc"
.ScreenUpdating = True
.Visible = True
.Documents.open filename:=Chr(34) & filename & Chr(34), _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:=""
CheckExistingFile SaveFilename
.activedocument.SaveAs filename:=SaveFilename
With .Selection
.HomeKey unit:=wdStory
Find oApp, "<Table1>"
.tables(1).Select
Set TheSourceRange = oApp.Selection.Range.Duplicate
: : : :
: : : :
: : : :
: : : :
: : : :
Set TheDestinationRange = oApp.Selection.Range
TheDestinationRange.FormattedText = TheSourceRange.FormattedText
End With
End With
Set oApp = Nothing
End Sub
If possible what I need is to record what's in the table to a memory variable, then use this to update the "TheDestinationRange"
Thank you for any help you can offer
Shane Brennan
I am application that uses the clipboard to copy and paste tables in Word. Which works fine - but once you use any other application and do Ctrl-C the clipboard gets overwritten and the application crashes.
Basically its a catalog system, where I ahve a template with a large A4 table, which I copy, fill in the details. If there is another record to write, I paste the table to get another blank form, fill it in, and so on.
Using the .copy and .paste is easy!
I've managed to come up with the following code where I can highlight a range and past it to another range - fully formatted. But with 1 problem - it's copying a fully completed table instead a blank one! Because it's copying what's in that range at that moment in time (I've cut the code down a little :
Private Sub Form_Load()
Dim filename As String
Dim SaveFilename As String
Dim TheSourceRange As Word.Range, TheDestinationRange As Word.Range
Set oApp = CreateObject("Word.Application")
With oApp
filename = "c:\temp\Catalogue Template.doc"
SaveFilename = "c:\Temp\Finished Report.doc"
.ScreenUpdating = True
.Visible = True
.Documents.open filename:=Chr(34) & filename & Chr(34), _
ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
WritePasswordDocument:="", WritePasswordTemplate:=""
CheckExistingFile SaveFilename
.activedocument.SaveAs filename:=SaveFilename
With .Selection
.HomeKey unit:=wdStory
Find oApp, "<Table1>"
.tables(1).Select
Set TheSourceRange = oApp.Selection.Range.Duplicate
: : : :
: : : :
: : : :
: : : :
: : : :
Set TheDestinationRange = oApp.Selection.Range
TheDestinationRange.FormattedText = TheSourceRange.FormattedText
End With
End With
Set oApp = Nothing
End Sub
If possible what I need is to record what's in the table to a memory variable, then use this to update the "TheDestinationRange"
Thank you for any help you can offer
Shane Brennan