ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   HELP - coding on Macro! (https://www.excelbanter.com/excel-worksheet-functions/177164-help-coding-macro.html)

Eric

HELP - coding on Macro!
 
The following coding is working, when the specific file is opened, there is
no need for the drive and directory for closing the file.

Workbooks.Open Filename:="E:\dir\File1.xls", UpdateLinks:=3
Workbooks("File1.xls").Close savechanges:=True

For the following code, it may contains the drive and directory, and not
able to close the file. Does anyone have any suggestions on how to fix the
code please?

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Thank you for any suggestions
Eric

Original Coding
================================================== ===
Option Explicit
Sub Temp2()

Dim myRng as Range
dim myCell as range
dim wkbk as workbook

with worksheets("sheet9999")
set myRng = .range("a2",.cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Workbooks("UpdateFiles").Close savechanges:=True

End Sub

================================================== ===

Dave Peterson

HELP - coding on Macro!
 
First, you have a response at your original thread.

Second, you'll want to copy the code you tried directly from the VBE and paste
it into the message window.



Eric wrote:

The following coding is working, when the specific file is opened, there is
no need for the drive and directory for closing the file.

Workbooks.Open Filename:="E:\dir\File1.xls", UpdateLinks:=3
Workbooks("File1.xls").Close savechanges:=True

For the following code, it may contains the drive and directory, and not
able to close the file. Does anyone have any suggestions on how to fix the
code please?

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Thank you for any suggestions
Eric

Original Coding
================================================== ===
Option Explicit
Sub Temp2()

Dim myRng as Range
dim myCell as range
dim wkbk as workbook

with worksheets("sheet9999")
set myRng = .range("a2",.cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Workbooks("UpdateFiles").Close savechanges:=True

End Sub

================================================== ===


--

Dave Peterson

Eric

HELP - coding on Macro!
 
Yes, I have done it, could you please check?
Thank you very much for any suggestions
Eric

"Dave Peterson" wrote:

First, you have a response at your original thread.

Second, you'll want to copy the code you tried directly from the VBE and paste
it into the message window.



Eric wrote:

The following coding is working, when the specific file is opened, there is
no need for the drive and directory for closing the file.

Workbooks.Open Filename:="E:\dir\File1.xls", UpdateLinks:=3
Workbooks("File1.xls").Close savechanges:=True

For the following code, it may contains the drive and directory, and not
able to close the file. Does anyone have any suggestions on how to fix the
code please?

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Thank you for any suggestions
Eric

Original Coding
================================================== ===
Option Explicit
Sub Temp2()

Dim myRng as Range
dim myCell as range
dim wkbk as workbook

with worksheets("sheet9999")
set myRng = .range("a2",.cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Workbooks("UpdateFiles").Close savechanges:=True

End Sub

================================================== ===


--

Dave Peterson


Dave Peterson

HELP - coding on Macro!
 
The code you posted in your earlier thread wasn't copied from the VBE--if it
was, then it was changed before you hit the send button.

Eric wrote:

Yes, I have done it, could you please check?
Thank you very much for any suggestions
Eric

"Dave Peterson" wrote:

First, you have a response at your original thread.

Second, you'll want to copy the code you tried directly from the VBE and paste
it into the message window.



Eric wrote:

The following coding is working, when the specific file is opened, there is
no need for the drive and directory for closing the file.

Workbooks.Open Filename:="E:\dir\File1.xls", UpdateLinks:=3
Workbooks("File1.xls").Close savechanges:=True

For the following code, it may contains the drive and directory, and not
able to close the file. Does anyone have any suggestions on how to fix the
code please?

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Thank you for any suggestions
Eric

Original Coding
================================================== ===
Option Explicit
Sub Temp2()

Dim myRng as Range
dim myCell as range
dim wkbk as workbook

with worksheets("sheet9999")
set myRng = .range("a2",.cells(.rows.count,"A").end(xlup))
end with

for each mycell in myrng.cells
set wkbk = Workbooks.Open (Filename:=mycell.value, UpdateLinks:=3)
wkbk.Close savechanges:=True
next mycell

Workbooks("UpdateFiles").Close savechanges:=True

End Sub

================================================== ===


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com