View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
ll ll is offline
external usenet poster
 
Posts: 67
Default pasting problems

Hi,
I am getting a "PasteSpecial method of Range class failed" message
when I run the following code. Could it have something to do with the
use of the code name?

Thanks
Louis
-----

Sub timesheetGenerate()

Dim LOldWb As Workbook
Dim LNewWb As Workbook
Dim x As Name

Dim wks As Worksheet
Dim CodeNameString As String

'Open existing timesheet :-)
Set LOldWb = Workbooks.Open(Filename:=UserForm1.TextBox1.Value)


'Add new workbook
Set LNewWb = Workbooks.Add


'///
'Copy sheet one of existing timesheet
LOldWb.Activate
For Each wks In LOldWb.Worksheets
CodeNameString = LCase(wks.CodeName)
If CodeNameString = "Sheet1" Then
LOldWb.Sheets(CodeNameString).Visible = True
LOldWb.Sheets(CodeNameString).Select

Cells.Select
'///replace formula with string
Selection.Replace What:="=", Replacement:="$$$$$=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False
'///copy all
Selection.Copy
End If
Next wks



'///
'Paste sheet one to new timesheet
LNewWb.Activate

For Each wks In LNewWb.Worksheets
CodeNameString = wks.CodeName
If CodeNameString = "Sheet1" Then
LNewWb.Sheets(CodeNameString).Visible = True
LNewWb.Sheets(CodeNameString).Select

Cells.Select
'///paste all (values)
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'///replace string with formula

Selection.Replace What:="$$$$$=", Replacement:="=", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False,
_
ReplaceFormat:=False

End If
Next wks

'\\\\
ActiveWorkbook.SaveAs Filename:=UserForm1.TextBox2.Value

'\\\\
ActiveWorkbook.Close

'\\\\
LOldWb.Activate

ActiveWorkbook.Close

End Sub