Hi
The idea behind the code below is to open an Excel sheet from Word. The Excel Sheet serves as an ini-file. The Excel is opened as visible = false. So far the code is working. But my problem is (see the bold passages) the "i"-counter. It changes but the value in xfilename "xfilename = objXLApp.workbooks("IntCoverage.xls").Worksheets("Coverage").Range("G" & i) & ".doc" stays always the same. If I open the Excel with visible = true it works. Is there also a solution with visible = false?
Thanks for you help
Michael
Sub Update()
Dim savename As String
Dim xfilename As String
Dim macro_name As String
Dim i As Integer
Dim objXLApp As Object
Set objXLApp = CreateObject(Class:="Excel.Application")
objXLApp.workbooks.Open ("R:\APS\AMR\REPB\IntCompanies\_Companies\IntCoverage.xls")
i = 9
Do
'objXLApp.workbooks.Active
xfilename = objXLApp.workbooks("IntCoverage.xls").Worksheets("Coverage").Range("G" & i) & ".doc"
macro_name = objXLApp.workbooks("IntCoverage.xls").Worksheets("Coverage").Range("E" & i) & "_"
savename = objXLApp.workbooks("IntCoverage.xls").Worksheets("Coverage").Range("C" & i) & "_1.doc"
If xfilename = ".doc" Then Exit Do
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder(xfilename)
If fs.FileExists(xfilename) = True Then
Documents.Open FileName:=(xfilename)
Application.Run MacroName:=(macro_name)
ActiveDocument.Save
ChangeFileOpenDirectory "R:\APS\AMR\REPB\IntCompanies\_Update\"
ActiveDocument.SaveAs FileName:=(savename), FileFormat:=wdFormatDocument, _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
End If
i = i + 1
Loop Until xfilename = ""
objXLApp.Quit
Set objXLApp = Nothing
Application.DisplayAlerts = True
End Sub
Bookmarks