compatiblity issue

  • Thread starter Thread starter Prabhu
  • Start date Start date
P

Prabhu

I have this code in EXCEL 2003. it is working fine when i run the same code
in 2000

word file got stuck and i cant able to proceed futher.

any one please help on this issue

Sub PasteToWordLS()

Dim AppWord As Word.Application
Dim wrdDoc As Word.Document

Dim LS As Long
Dim Letter1 As Long
Dim Statement1 As Integer
Dim Counter As Long

LS = 1
Letter1 = 1
Statement1 = 1



Sheets("Sheet1").Select
LS = ActiveSheet.UsedRange.Rows.count

Sheets("Sheet2").Select
Letter1 = ActiveSheet.UsedRange.Rows.count


Sheets("Sheet3").Select
Statement1 = ActiveSheet.UsedRange.Rows.count


Set AppWord = CreateObject("Word.Application")
AppWord.Visible = True

' Change the range to suit your needs. See the How to Use for this
code
Dim l1, l2 As Integer
Dim S1, S2 As Integer

Dim state As String

l1 = 1
l2 = 63
S1 = 1
S2 = 63
Counter = 1

Set wrdDoc = AppWord.Documents.Add
wrdDoc.PageSetup.BottomMargin = Application.CentimetersToPoints(0)
wrdDoc.PageSetup.TopMargin = Application.CentimetersToPoints(0)
wrdDoc.PageSetup.RightMargin = Application.CentimetersToPoints(0)
wrdDoc.PageSetup.LeftMargin = Application.CentimetersToPoints(0)


While Counter < LS

Sheets("Sheet1").Select
state = Range("D" & Counter).Value

If (state = "N") Then

Sheets("Sheet2").Range("A" & l1 & ":E" & l2).Copy

AppWord.Selection.Paste
Application.CutCopyMode = False
Application.DisplayAlerts = False

'Set AppWord = Nothing
l1 = l1 + 64
l2 = l2 + 64


End If


'-----------------------------------------------------------------------------

' Statement

If state = "Y" Then



Sheets("Sheet3").Range("A" & S1 & ":I" & S2).Copy
'Set wrdDoc = AppWord.Documents.Add

AppWord.Selection.Paste
Application.CutCopyMode = False
Application.DisplayAlerts = False
'Set AppWord = Nothing
S1 = S1 + 62
S2 = S2 + 62

End If


Counter = Counter + 63

Wend

MsgBox "Done"
End Sub
 
Prabhu,

The focus of this newsgroup is Macros in Access, the database program.
You will have a better chance of a good answer if you re-post to an
Excel related newsgroup.
 
Back
Top