Excel - consulta

 
Vista:

consulta

Publicado por Juan (9 intervenciones) el 30/12/2008 20:52:34
Hola, quisiera saber como es el codigo para una macro que me abra cualquier archivo existente desde excel a word.

saludos y gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de JuanC

RE:consulta

Publicado por JuanC (1237 intervenciones) el 30/12/2008 21:28:22
alguna vez hice esto...

Option Explicit
'//By JuanC - Ene. 2008
Sub SearchWordsInDoc()
Dim wDoc As Object
Dim wApp As Object
Dim fs As Variant
Dim lCount&, i&, sText$
Dim sFullName$, lOff&
Set fs = Application.FileSearch
Set wApp = GetWord
If wApp Is Nothing Then GoTo Fin
Application.ScreenUpdating = False
sText = "julio" '//Texto a buscar
Set fs = Application.FileSearch
With fs
.LookIn = "c:windowsescritorio" '//Carpeta de búsqueda
.SearchSubFolders = True
.Filename = "*.doc"
If .Execute(SortBy:=msoSortByLastModified, SortOrder:=msoSortOrderAscending, AlwaysAccurate:=True) > 0 Then
lCount = .FoundFiles.Count
For i = 1 To lCount
sFullName = .FoundFiles(i)
Set wDoc = wApp.Documents.Open(sFullName)
If Not wDoc Is Nothing Then
If FindText(wDoc, sText) Then
[A1].Offset(lOff).Hyperlinks.Add Anchor:=[A1].Offset(lOff), Address:=wDoc.FullName, TextToDisplay:=Mid(sFullName, InStrRev(sFullName, "") + 1)
lOff = lOff + 1
End If
wDoc.Close False
End If
Next
End If
End With
wApp.Quit
Fin:
Application.ScreenUpdating = True
Set fs = Nothing
Set wApp = Nothing
Set wDoc = Nothing
End Sub
Private Function GetWord() As Object
On Error GoTo Create
Set GetWord = GetObject(, "Word.Application")
Exit Function
Create:
Set GetWord = CreateObject("Word.Application")
End Function
Private Function FindText(ByVal Doc As Object, ByVal sText As String) As Boolean
On Error Resume Next
With Doc.Content.Find
.ClearFormatting
If .Execute(FindText:=sText) Then
FindText = True
Else
FindText = False
End If
End With
End Function

Saludos desde Baires, JuanC
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:consulta

Publicado por juan (9 intervenciones) el 30/12/2008 21:41:21
Hola muchas gracias; pero fijate que probe el codigo que me enviastes y me da un error, que me dice "Se ha producido el error '445' en tiempo de ejecucion
El objeto no admite esta accion"

ayudame please porfa

gracias

saludoss
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar