Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Why these commands make erros? (Breaklink and SaveAs)


I've found many useful codes in this forum and used them to create the
following macro. But it's making erros because of a my modifications to
the codes i've found.

HOW IT WORKS:
Cell D6 contains de path to search the files.
Cell D10 and D12 contains the first and last part of the name to be
used as criteria of the filesearch.
Cell D8 contains the path where the file is going to be saved after the
links are updated and broken.

PROBLEMS:
I don't know how to make the breaklink function break all links of the
file.
The ActiveWorkbook.SaveAs function is not working well because it is
not saving the file in the path entered in the Cell D8.

CODE:
Sub Update()

Set fs = Application.FileSearch
With fs
..LookIn = Range("D6").Value
..Filename = Range("D10").Value & "*" & Range("D12").Value
If .Execute 0 Then
For i = 1 To .FoundFiles.Count

nm = Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1, _
Len(.FoundFiles(i)))

MsgBox Range("D8").Value & nm 'The name of the path with the filename
is correct

Workbooks.Open (.FoundFiles(i))
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
ActiveWorkbook.SaveAs Filename:=Range("D8").Value & nm

Dim astrLinks As Variant
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLi nks)
For b = 1 To .linksourses.Count
ActiveWorkbook.BreakLink _
Name:=astrLinks(b), _
Type:=xlLinkTypeExcelLinks
Next b

MsgBox nm & " updated."

ActiveWindow.Close

Next i
Else
MsgBox "There are no files in this directory."
End If
End With

End Sub


--
pauloreiss
------------------------------------------------------------------------
pauloreiss's Profile: http://www.excelforum.com/member.php...o&userid=29820
View this thread: http://www.excelforum.com/showthread...hreadid=497962

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Why these commands make erros? (Breaklink and SaveAs)

I try to qualify the ranges mo

ActiveWorkbook.SaveAs Filename:=Range("D8").Value & nm
becomes:
ActiveWorkbook.SaveAs _
Filename:=thisworkbook.worksheets("sheet99").Range ("D8").Value & nm

Thisworkbook is the workbook with code
change sheet99 to the name of the worksheet with the list.

pauloreiss wrote:

I've found many useful codes in this forum and used them to create the
following macro. But it's making erros because of a my modifications to
the codes i've found.

HOW IT WORKS:
Cell D6 contains de path to search the files.
Cell D10 and D12 contains the first and last part of the name to be
used as criteria of the filesearch.
Cell D8 contains the path where the file is going to be saved after the
links are updated and broken.

PROBLEMS:
I don't know how to make the breaklink function break all links of the
file.
The ActiveWorkbook.SaveAs function is not working well because it is
not saving the file in the path entered in the Cell D8.

CODE:
Sub Update()

Set fs = Application.FileSearch
With fs
LookIn = Range("D6").Value
Filename = Range("D10").Value & "*" & Range("D12").Value
If .Execute 0 Then
For i = 1 To .FoundFiles.Count

nm = Mid(.FoundFiles(i), InStrRev(.FoundFiles(i), "\") + 1, _
Len(.FoundFiles(i)))

MsgBox Range("D8").Value & nm 'The name of the path with the filename
is correct

Workbooks.Open (.FoundFiles(i))
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
ActiveWorkbook.SaveAs Filename:=Range("D8").Value & nm

Dim astrLinks As Variant
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLi nks)
For b = 1 To .linksourses.Count
ActiveWorkbook.BreakLink _
Name:=astrLinks(b), _
Type:=xlLinkTypeExcelLinks
Next b

MsgBox nm & " updated."

ActiveWindow.Close

Next i
Else
MsgBox "There are no files in this directory."
End If
End With

End Sub

--
pauloreiss
------------------------------------------------------------------------
pauloreiss's Profile: http://www.excelforum.com/member.php...o&userid=29820
View this thread: http://www.excelforum.com/showthread...hreadid=497962


--

Dave Peterson
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
Vlookup Erros KMJ Excel Discussion (Misc queries) 2 November 5th 09 12:11 AM
Formula erros =#N/A Tia[_3_] Excel Worksheet Functions 2 June 4th 08 04:25 PM
Trapping Erros on ChangeLinks qwerty[_2_] Excel Programming 1 November 12th 05 02:07 AM


All times are GMT +1. The time now is 04:41 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"