Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with strange behaviour of macro


Hi

I got a macro that produces 54 word documents which are linked to
workbook full of data. the macro runs perfectly except it does not see
to break the links between word and excel but only on certain tables an
graphs.

this is my code I have at the moment
Option Explicit

Sub runReports()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim rng As Word.Range
Dim cel As Object
Dim strStoreDoing As String
Dim sheet As Worksheet
Dim counter As Integer

'open word
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
'loop through cell Stores wanted
For Each cel In Range("todoStore") ' This is a list of stores whic
I want to produce
Sheets("main").Range("e16").Value = cel.Value
strStoreDoing = Sheets("main").Range("e17").Value


Application.ScreenUpdating = False


'miss certain stores
If (cel.Value + 0) 1000 Then GoTo donotdoStore
'open word template
Set wrdDoc = wrdApp.Documents.Open(ThisWorkbook.Path
"\wrdStore.doc")
Set rng = wrdApp.ActiveDocument.Range

'Loop through sheets and autofilter the data according to which stor
you producing
For Each sheet In Sheets(Array("Sheet1", "sheet2", "sheet3", _
"sheet4"))
sheet.Select
Range("a1").Select
Selection.AutoFilter Field:=4, Criteria1:=strstoreDoing

Next sheet

'unlink fields
rng.Fields.Unlink
'unlink header and footers
' doHeadFoot
' wrdApp.ActiveDocument.Shapes("Text Box 22").Select
wrdApp.Selection.Fields.Unlink

'save as Store name
wrdDoc.SaveAs (ThisWorkbook.Path & "\reports\" & LCase(strCrtDoing
& " apr 2005 to mar 2006.doc")
wrdDoc.Close
'wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing

' turn the Autofilters to All
For Each sheet In Sheets(Array("Sheet1", "sheet2", "sheet3", _
"sheet4"))
sheet.Select
Range("a1").Select
Selection.AutoFilter Field:=4

Next sheet

Application.ScreenUpdating = True
Sheets("main").Activate
Range("c13").Value = cel.Value
Next cel
donotdoSto
Set wrdApp = Nothing
End Sub

Sub doHeadFoot()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
Dim x As Integer
Dim z

For Each oSection In ActiveDocument.Sections
x = x + 1
If x = 1 Then GoTo missfirst:

For Each oHeader In oSection.Headers
If oHeader.Exists Then
If oHeader.Index = 0 Then GoTo missheader:
For Each oField In oHeader.Range.Fields
oField.Unlink
Next oField
missheader:
End If
Next oHeader

For Each oFooter In oSection.Footers
If oFooter.Exists Then
If oFooter.Index = 0 Then GoTo missfooter:
For Each oField In oFooter.Range.Fields
If Left(oField.Code, 5) = " LINK" Then oField.Unlink
Next oField
missfooter:
End If
Next oFooter

missfirst:
Next oSection


End Sub




Any help much appreciated

--
funkymonkU
-----------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...fo&userid=1813
View this thread: http://www.excelforum.com/showthread.php?threadid=52897

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default help with strange behaviour of macro


can anybody help this is really causing me a problem,. it almost seems
as if it only selects certain things to unlink.


--
funkymonkUK
------------------------------------------------------------------------
funkymonkUK's Profile: http://www.excelforum.com/member.php...o&userid=18135
View this thread: http://www.excelforum.com/showthread...hreadid=528979

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
find and replace macro strange behaviour Nicawette Excel Discussion (Misc queries) 3 June 13th 06 08:49 PM
Strange VBA Behaviour Ricko Excel Programming 0 July 28th 05 07:53 AM
Strange behaviour Edgar Thoemmes Excel Worksheet Functions 1 February 8th 05 03:20 PM
Strange behaviour in VBA Help Michael Singmin Excel Programming 4 June 4th 04 07:06 PM
strange behaviour Patrick Molloy Excel Programming 0 September 4th 03 07:51 AM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"