Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Change links for batch of workbooks

Hi everyone,

I'm hoping someone can help me out.

I've got about 40 workbooks each with between 7 and 11 sheets.

The workbooks originally just held data and new (analysis) sheets were added
from a template.

The analysis sheets have lookup formulas relating back to the original
template.

If it is possible I would be grateful for someone to help me with code that
can go through each of the workbooks (all in the same folder) and change the
link from the template link to the data in the same workbook.

I've found this bit of code in this forum and it does what I want but it's
just as easy to go into the menus and do it that way.

Thanks
Trish

Sub LinksChangeSourcewitherrortrap()

Dim stroldlink As String
Dim strnewlink As String
MsgBox "Select Original link Sourcexxx"

stroldlink = Application.GetOpenFilename _
("Excel files,*.xls")
MsgBox "Select workbook to change"

strnewlink = Application.GetOpenFilename _
("Excel files,*.xls")

MsgBox ActiveWorkbook.Name

On Error GoTo errorLinks 'No colon after label name here
ActiveWorkbook.ChangeLink Name:=stroldlink, _
newname:=strnewlink, _
Type:=xlLinkTypeExcelLinks ' This one works at work

On Error GoTo 0 'Cancels the error call.

Exit Sub 'Place this immediately before errorLinks
'label so does not process unless there is an error.

errorLinks: 'Note the colon after the label name

MsgBox "An error has occurred. " & _
"This is possibly due to one of the following:-" _
& Chr(13) & "Incorrect Workbook name selected and/or" _
& Chr(13) & "Workbooks do not have same Worksheet names." _
& Chr(13) & "Check both the above and then re-run the macro."

End Sub

--
Trish
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Change links for batch of workbooks

Hi Trish

See
http://www.rondebruin.nl/copy4.htm

You can change the red code block to code that make your changes

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Trish Smith" wrote in message ...
Hi everyone,

I'm hoping someone can help me out.

I've got about 40 workbooks each with between 7 and 11 sheets.

The workbooks originally just held data and new (analysis) sheets were added
from a template.

The analysis sheets have lookup formulas relating back to the original
template.

If it is possible I would be grateful for someone to help me with code that
can go through each of the workbooks (all in the same folder) and change the
link from the template link to the data in the same workbook.

I've found this bit of code in this forum and it does what I want but it's
just as easy to go into the menus and do it that way.

Thanks
Trish

Sub LinksChangeSourcewitherrortrap()

Dim stroldlink As String
Dim strnewlink As String
MsgBox "Select Original link Sourcexxx"

stroldlink = Application.GetOpenFilename _
("Excel files,*.xls")
MsgBox "Select workbook to change"

strnewlink = Application.GetOpenFilename _
("Excel files,*.xls")

MsgBox ActiveWorkbook.Name

On Error GoTo errorLinks 'No colon after label name here
ActiveWorkbook.ChangeLink Name:=stroldlink, _
newname:=strnewlink, _
Type:=xlLinkTypeExcelLinks ' This one works at work

On Error GoTo 0 'Cancels the error call.

Exit Sub 'Place this immediately before errorLinks
'label so does not process unless there is an error.

errorLinks: 'Note the colon after the label name

MsgBox "An error has occurred. " & _
"This is possibly due to one of the following:-" _
& Chr(13) & "Incorrect Workbook name selected and/or" _
& Chr(13) & "Workbooks do not have same Worksheet names." _
& Chr(13) & "Check both the above and then re-run the macro."

End Sub

--
Trish

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Change links for batch of workbooks

Thanks Ron,

Looks just the job!

Thanks again

--
Trish


"Ron de Bruin" wrote:

Hi Trish

See
http://www.rondebruin.nl/copy4.htm

You can change the red code block to code that make your changes

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm


"Trish Smith" wrote in message ...
Hi everyone,

I'm hoping someone can help me out.

I've got about 40 workbooks each with between 7 and 11 sheets.

The workbooks originally just held data and new (analysis) sheets were added
from a template.

The analysis sheets have lookup formulas relating back to the original
template.

If it is possible I would be grateful for someone to help me with code that
can go through each of the workbooks (all in the same folder) and change the
link from the template link to the data in the same workbook.

I've found this bit of code in this forum and it does what I want but it's
just as easy to go into the menus and do it that way.

Thanks
Trish

Sub LinksChangeSourcewitherrortrap()

Dim stroldlink As String
Dim strnewlink As String
MsgBox "Select Original link Sourcexxx"

stroldlink = Application.GetOpenFilename _
("Excel files,*.xls")
MsgBox "Select workbook to change"

strnewlink = Application.GetOpenFilename _
("Excel files,*.xls")

MsgBox ActiveWorkbook.Name

On Error GoTo errorLinks 'No colon after label name here
ActiveWorkbook.ChangeLink Name:=stroldlink, _
newname:=strnewlink, _
Type:=xlLinkTypeExcelLinks ' This one works at work

On Error GoTo 0 'Cancels the error call.

Exit Sub 'Place this immediately before errorLinks
'label so does not process unless there is an error.

errorLinks: 'Note the colon after the label name

MsgBox "An error has occurred. " & _
"This is possibly due to one of the following:-" _
& Chr(13) & "Incorrect Workbook name selected and/or" _
& Chr(13) & "Workbooks do not have same Worksheet names." _
& Chr(13) & "Check both the above and then re-run the macro."

End Sub

--
Trish


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
Links to Excel Workbooks change Renee Voice Excel Discussion (Misc queries) 0 January 19th 12 03:59 AM
How do I change the links in Excel at one batch? LunaMoon Excel Discussion (Misc queries) 1 April 24th 10 12:59 AM
Slow opening links between workbooks with links created in 2003 Russell Excel Discussion (Misc queries) 0 December 14th 09 02:59 PM
Need2 batch print all the workbooks in 25 worksheets in one step richie s. Excel Discussion (Misc queries) 2 June 26th 06 03:46 PM
macro to batch fix errors on password protected workbooks spence Excel Programming 4 October 7th 05 04:06 AM


All times are GMT +1. The time now is 05:46 PM.

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"