Dim WordApp As New Word.Application
Dim WordDoc As Word.Document
Dim CType As String, CFile As String
Dim dirpath As String
Dim kname As String
Dim par1 As String
Dim par2 As String
par1 = ActiveWorkbook.Sheets("Ñïèñîê çàìåíû").Cells(5, 2).Value
par2 = ActiveWorkbook.Sheets("Ñïèñîê çàìåíû").Cells(5, 3).Value
dirpath = ActiveWorkbook.Sheets("Ñïèñîê çàìåíû").Cells(63, 2).Value
fname1 = ActiveWorkbook.Sheets("Ñïèñîê çàìåíû").Cells(64, 2).Value
With WordApp
.Visible = True
.WindowState = wdWindowStateMaximize
CFile = dirpath & "\" & fname1 & ".doc"
Set WordDoc = .Documents.Open(CFile)
End With
WordDoc.Activate
With WordApp.ActiveDocument.Content.Find
.Text = par1
.Replacement.Text = par2
.Execute Replace:=wdReplaceAll
End With
Sub Кнопка1_Щелкнуть()
Dim She As Variant
Set She = GetObject("path-filename.doc")
She.OLEOpen ActiveSheet.Cells(2, 1), ActiveSheet.Cells(2, 2)
'See.ActiveDocument.Save
End Sub
Function OLEOpen(par1 As String, par2 As String)
Content.Find.Execute FindText:=par1, ReplaceWith:=par2, Replace:=wdReplaceAll
End Function
sFilename = Application.GetOpenFilename("All files (*.*), *.*")
' To Exit if Cancel was pressed
If sFilename = False Then Exit Sub
' -- alternatively -- can use
With Application.Dialogs(xlDialogOpen)
.Show
End With
Dim startdir As String
Private Sub HDD1_Click() 'переключатель для выбора локальных дисков
startdir = "e:\" ' replace with starting directory
Call Список_каталогов
End Sub
Private Sub Список_каталогов()
Dim aryFoundDirectories() As String
Директории.AddItem Application.DefaultFilePath
On Error GoTo NEXT_STEP
' find all directories and subdirs from a starting point
current = 0
dircount = 0
currentdir = startdir
While current <= dircount
subdirect = Dir(currentdir, vbDirectory + vbHidden)
While subdirect <> ""
If subdirect <> "." And subdirect <> ".." Then
If (GetAttr(currentdir & subdirect) And vbDirectory) = vbDirectory Then
dircount = dircount + 1
ReDim Preserve aryFoundDirectories(dircount)
aryFoundDirectories(dircount) = currentdir & subdirect & "\"
End If
End If
subdirect = Dir
Wend
current = current + 1
currentdir = aryFoundDirectories(current)
Wend
dircount = dircount + 1
ReDim Preserve aryFoundDirectories(dircount)
aryFoundDirectories(dircount) = startdir
NEXT_STEP:
Браузер.Директории.Clear
For i = 1 To UBound(aryFoundDirectories())
Браузер.Директории.AddItem aryFoundDirectories(i) 'комбо-бокс для имён каталогов
Next
End Sub
Private Sub Директории_Change() 'Имена файлов
Dim FileArray() As String, ffile As String, Count As Integer
Count = 0
ffile = Dir(Директории.Text, vbDirectory)
ReDim FileArray(Count)
FileArray(Count) = LCase(ffile)
Count = 1
Do While ffile <> ""
ffile = Dir()
If ffile <> "." And ffile <> ". ." Then
ReDim Preserve FileArray(Count)
FileArray(Count) = LCase(ffile)
Count = Count + 1
End If
Loop
Браузер.Файлы.Clear
For i = LBound(FileArray()) To UBound(FileArray())
Браузер.Файлы.AddItem FileArray(i) 'список для имён файлов
Next
End Sub
Sub Список_каталогов()
startdir = Каталоги.Text 'Указывает путь из выбранного комбо-бокса
Папка.Clear
Файлы.Clear
ChDir startdir
MyName = Dir("*.*", vbDirectory) ' Возвращает первый элемент
Do While MyName <> "" ' Начинает цикл
'Игнорирует текущий каталог и каталог предыдущего уровня
If MyName <> "." And MyName <> ".." Then
'Выводит элемент в список каталогов если это каталог
If (GetAttr(startdir & "\" & MyName) And vbDirectory) = vbDirectory Then
Папка.AddItem MyName
'Выводит элемент в список файлов если это файл
ElseIf (GetAttr(startdir & "\" & MyName) And vbNormal) = vbNormal Then
Файлы.AddItem MyName
End If
End If
MyName = Dir 'Возвращает следующий элемент.
Loop
End Sub
Tables(i).Rows.Count
doevents?
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 42