compileerfout: kan niet toewijzen aan een alleen lezen eigenschap

Status
Niet open voor verdere reacties.

nicodw

Nieuwe gebruiker
Lid geworden
18 feb 2013
Berichten
4
Hallo,

ik gebruik volgende code om vanuit word excel tabellen in het word document te plaatsen (deed het perfect in 2003)

de eerste, Macro10 doet het nog
de tweede Macro10_4 doet het niet

er wordt een compileerfout aangegeven bij path: de tekst erbij is kan niet toewijzen aan een alleen-lezen eigenschap.
Voor mij lijken de twee codes identiek?

alvast bedankt

Nico

Sub Macro10()

'
Dim Path

'Zoeken van tabel001
Selection.Find.ClearFormatting
With Selection.Find
.Text = "{{tabel006}}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


'Excel starten en wokrbook openen



Set xlApp = CreateObject("Excel.Application")

'You do not need to make the application object visible
'if you close the file and quit the application
'later in your code, in order to remove these objects
'from memory.

With xlApp
.Visible = True

'START eerste tabel invoegen uit excel invoegen in Word
Path = "C:\spss\tabel\tabel006.xls"
.Workbooks.Open Path

.Range("A7:C10").Select
.Selection.Copy

Selection.PasteExcelTable False, False, False
'Prevent Excel from prompting to save changes
'to the workbook when the user quits.
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
'EINDE eerste tabel invoegen uit excel invoegen in Word




.Quit
End With

End Sub

Sub Macro10_4()

'Zoeken van tabel004
Selection.Find.ClearFormatting
With Selection.Find
.Text = "{{tabel004}}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


'Excel starten en wokrbook openen



Set xlApp = CreateObject("Excel.Application")

'You do not need to make the application object visible
'if you close the file and quit the application
'later in your code, in order to remove these objects
'from memory.

With xlApp
.Visible = True

'START eerste tabel invoegen uit excel invoegen in Word
Path = "C:\spss\tabel\tabel004.xls"

.Workbooks.Open Path

.Range("A9:E10").Select
.Selection.Copy

Selection.PasteExcelTable False, False, False
'Prevent Excel from prompting to save changes
'to the workbook when the user quits.
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
'EINDE eerste tabel invoegen uit excel invoegen in Word




.Quit
End With

End Sub
 
Doe ons een lol, en maak de code op met de code knop; dit is onleesbaar.
 
zoiets?

Code:
Sub Macro10()

'
Dim Path

'Zoeken van tabel001
Selection.Find.ClearFormatting
With Selection.Find
.Text = "{{tabel006}}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


'Excel starten en wokrbook openen



Set xlApp = CreateObject("Excel.Application")

'You do not need to make the application object visible
'if you close the file and quit the application
'later in your code, in order to remove these objects
'from memory.

With xlApp
.Visible = True

'START eerste tabel invoegen uit excel invoegen in Word
Path = "C:\spss\tabel\tabel006.xls"
.Workbooks.Open Path

.Range("A7:C10").Select
.Selection.Copy

Selection.PasteExcelTable False, False, False
'Prevent Excel from prompting to save changes
'to the workbook when the user quits.
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
'EINDE eerste tabel invoegen uit excel invoegen in Word




.Quit
End With

End Sub

Sub Macro10_4()

'Zoeken van tabel004
Selection.Find.ClearFormatting
With Selection.Find
.Text = "{{tabel004}}"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


'Excel starten en wokrbook openen



Set xlApp = CreateObject("Excel.Application")

'You do not need to make the application object visible
'if you close the file and quit the application
'later in your code, in order to remove these objects
'from memory.

With xlApp
.Visible = True

'START eerste tabel invoegen uit excel invoegen in Word
Path = "C:\spss\tabel\tabel004.xls"

.Workbooks.Open Path

.Range("A9:E10").Select
.Selection.Copy

Selection.PasteExcelTable False, False, False
'Prevent Excel from prompting to save changes
'to the workbook when the user quits.
.ActiveWorkbook.Saved = True
.ActiveWorkbook.Close
'EINDE eerste tabel invoegen uit excel invoegen in Word




.Quit
End With

End Sub
 
"Path' is een gereserveerde naam in VBA.
Geef een variabele nooit zo'n naam.

Bovendien is het gebruik van deze 'variabele' in jouw code volstrekt overbodig.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan