S
SAm
Hi
I have some code and i don't know why sometimes i get errors, sometimes i
can get parts of it to work. the objective: run a report, save it as a word
document, then copy it on to the clipboard, and delete the file. then i want
to start a new excel spreadsheet, paste my clipboard in it, and save it. then
i will add more code which is not written yet.
this is the code:
Code:
Set MyWordInstance = New Word.Application
MyWordInstance.Documents.Open "C:\tempRpt.rtf"
With MyWordInstance
.Selection.WholeStory
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
End With
.Selection.Find.Execute Replace:=wdReplaceAll
.Selection.WholeStory
.Selection.Copy
End With
MyWordInstance.ActiveDocument.Close
MyWordInstance.Quit
'Kill "C:\tempPayperiodRpt.rtf"
Set MyExcelInstance = New Excel.Application
MyExcelInstance.Workbooks.Add
MyExcelInstance.ActiveWorkbook.SaveAs "C:\PPP"
MyExcelInstance.ActiveWorkbook.ActiveSheet.Range("B5").Select
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("B5")
MyExcelInstance.ActiveWorkbook.Save
MyExcelInstance.ActiveWorkbook.Close
MyExcelInstance.Quit
I have some code and i don't know why sometimes i get errors, sometimes i
can get parts of it to work. the objective: run a report, save it as a word
document, then copy it on to the clipboard, and delete the file. then i want
to start a new excel spreadsheet, paste my clipboard in it, and save it. then
i will add more code which is not written yet.
this is the code:
Code:
Set MyWordInstance = New Word.Application
MyWordInstance.Documents.Open "C:\tempRpt.rtf"
With MyWordInstance
.Selection.WholeStory
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
With .Selection.Find
.Text = "^m"
.Replacement.Text = ""
.Forward = True
End With
.Selection.Find.Execute Replace:=wdReplaceAll
.Selection.WholeStory
.Selection.Copy
End With
MyWordInstance.ActiveDocument.Close
MyWordInstance.Quit
'Kill "C:\tempPayperiodRpt.rtf"
Set MyExcelInstance = New Excel.Application
MyExcelInstance.Workbooks.Add
MyExcelInstance.ActiveWorkbook.SaveAs "C:\PPP"
MyExcelInstance.ActiveWorkbook.ActiveSheet.Range("B5").Select
ActiveSheet.Paste Destination:=Worksheets("Sheet1").Range("B5")
MyExcelInstance.ActiveWorkbook.Save
MyExcelInstance.ActiveWorkbook.Close
MyExcelInstance.Quit