• DİKKAT

    DOSYA İndirmek/Yüklemek için ÜCRETLİ ALTIN ÜYELİK Gereklidir!
    Altın Üyelik Hakkında Bilgi

Makro ile word dosyasına klasördeki resimleri eklemek

  • Konbuyu başlatan Konbuyu başlatan halit3
  • Başlangıç tarihi Başlangıç tarihi

halit3

Uzman
Uzman
Katılım
18 Ocak 2008
Mesajlar
12,878
Excel Vers. ve Dili
2003 excell türkçe
ve
2007 excell türkçe
Makro ile word dosyasına klasördeki resimleri eklemek ile ilgili çalışma

kod:

Kod:
Dim klasor2(50000)
Dim saydır


Sub worde_resim_al()

Set Klasor = CreateObject("shell.application").BrowseForFolder(0, "Kaynak Dosyaları İçeren Klasörü Seçin", 50, &H0)
If Not Klasor Is Nothing Then
Kaynak = Klasor.self.Path
If InStr(1, Kaynak, "{") > 0 Then GoTo Atla

saydır = 0
Liste (Kaynak)

Dim fL As Object, fs As Object, f As Object
Set fL = CreateObject("Scripting.FileSystemObject")

yol = ThisWorkbook.Path & "\"
sayi = Application.InputBox("Kaç adet sütun eklenecek.", "Sayı giriniz.", "2", 400, 30, , Type:=1)
   
If sayi = False Then
MsgBox "İşlemi iptal ettiniz"
Exit Sub
End If

msg1 = MsgBox("Sayfayı DİKEY yapmak için  EVET  tıklayınız. " & Chr(10) & Chr(10) & _
"Sayfayı YATAY yapmak için  HAYIR  tıklayınız.", vbYesNo + vbInformation, "u y a r ı !")

Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
wrdApp.Visible = True
With wrdDoc
.Content.InsertParagraphAfter
With wrdApp.ActiveDocument

With wrdApp.ActiveDocument.PageSetup
.LeftMargin = 15 '50 'sol
.RightMargin = 10 '50 'sağ
.TopMargin = 15 'üst
.BottomMargin = 10 '20 ' alt

If msg1 = vbYes Then
.Orientation = wdOrientPortrait
yükseylik = 189
Else
.Orientation = wdOrientLandscape
yükseylik = 175
End If

End With

With wrdApp.ActiveDocument

Set myRange = wrdApp.ActiveDocument.Range(0, 0)
wrdApp.ActiveDocument.Tables.Add Range:=myRange, NumRows:=2, NumColumns:=sayi

With wrdApp.ActiveDocument.Tables(1)
If .Style <> "Tablo Kılavuzu" Then
.Style = "Tablo Kılavuzu"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With
End With

ekle1 = 0
sat = 0
say = 0

For i = 1 To saydır

For Each Dosya In fL.getfolder(klasor2(i)).Files

If LCase(fL.GetExtensionName(Dosya)) = "jpg" Or LCase(fL.GetExtensionName(Dosya)) = "bmp" Then
say = say + 1
If say Mod sayi = 1 Then
sut = 1
sat = sat + 1 + ekle1
ekle1 = 1
son = wrdApp.ActiveDocument.Tables(1).Rows.Count ' satır kontrol
If wrdApp.ActiveDocument.Tables.Count >= 1 Then
If say > 1 Then
wrdApp.ActiveDocument.Sections(1).Range.Tables(1).Rows.Last.Select
wrdApp.Selection.InsertRowsBelow 2
End If
End If
Else
sut = sut + 1
End If


With wrdApp.ActiveDocument.Tables.Item(1).Cell(sat + 1, sut)
.Range = fL.GetBaseName(Dosya)
End With

With wrdApp.ActiveDocument.Tables.Item(1).Cell(sat, sut)
.Range.Paragraphs.WordWrap = True
.Range.InlineShapes.AddPicture Filename:=Dosya, LinkToFile:=False, SaveWithDocument:=True
.Range.InlineShapes(1).Fill.Visible = msoFalse
.Range.InlineShapes(1).Fill.Solid
.Range.InlineShapes(1).Line.Visible = msoFalse
.Range.InlineShapes(1).Height = yükseylik
.Range.InlineShapes(1).Width = .Range.Cells.Width - 6
End With

End If
Next
Next

End With

son1 = CreateObject("Scripting.FileSystemObject").getfolder(ThisWorkbook.Path).Files.Count + 1
dosya_adi = ThisWorkbook.Path & "\" & "word dosya" & son1 & ".doc"
wrdApp.ActiveDocument.SaveAs dosya_adi

End With

wrdApp.Documents(wrdDoc.Name).Activate

Set Klasor = Nothing
MsgBox "işlem tamam"
Else
Atla:
MsgBox "Lütfen Kaynak Klasör Seçimini Yapınız !", vbInformation, "DİKKAT"
End If


End Sub

Private Sub Liste(yol As String)
Dim fL As Object, fs As Object, f As Object, j As Long, n As Long
Set fL = CreateObject("Scripting.FileSystemObject")

saydır = saydır + 1
klasor2(saydır) = yol
sonraki:
For Each f In fL.getfolder(yol).subfolders
Liste (f.Path)
On Error GoTo sonraki
Next

End Sub
 

Ekli dosyalar

  • worde resim al.xls
    worde resim al.xls
    39.5 KB · Görüntüleme: 41
  • Yeni Bit Eşlem Resmi.jpg
    Yeni Bit Eşlem Resmi.jpg
    207.7 KB · Görüntüleme: 5
Son düzenleme:
Halit hocam elinize gönlünüze sağlık. Güzel bir çalışma yine döktürmüşsünüz.
 
Harikasınız Halit3 Hocam,
Teşekkürler
Saygılarımla
 
Halit3 bey çok güzel program. Acaba sizden bir kaç şey daha isteyebilir miyim?
1. si isminin eklenmesini istemiyorum. Sadece kaçıncı resim se 1 2 3 diye resimden önce yazsın.
2. si tablo olmadan alt alta eklenebilir mi ve eklenirken en boy oranı sabit kalacak şekilde ve eni sütun genişliği ayarında yaparak yapılabilir mi?
 
Halit3 bey çok güzel program. Acaba sizden bir kaç şey daha isteyebilir miyim?
1. si isminin eklenmesini istemiyorum. Sadece kaçıncı resim se 1 2 3 diye resimden önce yazsın.
2. si tablo olmadan alt alta eklenebilir mi ve eklenirken en boy oranı sabit kalacak şekilde ve eni sütun genişliği ayarında yaparak yapılabilir mi?

Kodun aşağıdaki kırmızı yerleriyle oynayınız.

Kod:
Dim klasor2(50000)
Dim saydır


Sub worde_resim_al5()

Set Klasor = CreateObject("shell.application").BrowseForFolder(0, "Kaynak Dosyaları İçeren Klasörü Seçin", 50, &H0)
If Not Klasor Is Nothing Then
Kaynak = Klasor.self.Path
If InStr(1, Kaynak, "{") > 0 Then GoTo Atla

saydır = 0
Liste (Kaynak)

Dim fL As Object, fs As Object, f As Object
Set fL = CreateObject("Scripting.FileSystemObject")

yol = ThisWorkbook.Path & "\"

msg1 = MsgBox("Sayfayı DİKEY yapmak için  EVET  tıklayınız. " & Chr(10) & Chr(10) & _
"Sayfayı YATAY yapmak için  HAYIR  tıklayınız.", vbYesNo + vbInformation, "u y a r ı !")

Set wrdApp = CreateObject("Word.Application")
Set wrdDoc = wrdApp.Documents.Add
wrdApp.Visible = True
With wrdDoc
.Content.InsertParagraphAfter
With wrdApp.ActiveDocument

With wrdApp.ActiveDocument.PageSetup
.LeftMargin = 15 '50 'sol
.RightMargin = 10 '50 'sağ
.TopMargin = 15 'üst
.BottomMargin = 10 '20 ' alt

If msg1 = vbYes Then
.Orientation = wdOrientPortrait
yükseylik = 189
Else
.Orientation = wdOrientLandscape
yükseylik = 175
End If

End With

say = 0

For i = 1 To saydır
For Each Dosya In fL.getfolder(klasor2(i)).Files

If LCase(fL.GetExtensionName(Dosya)) = "jpg" Or LCase(fL.GetExtensionName(Dosya)) = "bmp" Then
say = say + 1
wrdApp.Selection.TypeText Text:="" & say & ""
wrdApp.Selection.TypeParagraph
wrdApp.Selection.InlineShapes.AddPicture Filename:=Dosya, LinkToFile:=False, SaveWithDocument:=True
With wrdApp.ActiveDocument.InlineShapes(say)
.Fill.Visible = msoFalse
.Fill.Solid
.Line.Visible = msoFalse
.LockAspectRatio = msoTrue
'.Height = [COLOR="red"]150[/COLOR]
.Width = wrdApp.ActiveDocument.PageSetup.PageWidth - [COLOR="Red"]30[/COLOR] '550
End With
wrdApp.Selection.TypeText Text:=Chr(10)

End If
Next
Next

End With

son1 = CreateObject("Scripting.FileSystemObject").getfolder(ThisWorkbook.Path).Files.Count + 1
dosya_adi = ThisWorkbook.Path & "\" & "word dosya" & son1 & ".doc"
wrdApp.ActiveDocument.SaveAs dosya_adi

End With

wrdApp.Documents(wrdDoc.Name).Activate

Set Klasor = Nothing
MsgBox "işlem tamam"
Else
Atla:
MsgBox "Lütfen Kaynak Klasör Seçimini Yapınız !", vbInformation, "DİKKAT"
End If


End Sub

Private Sub Liste(yol As String)
Dim fL As Object, fs As Object, f As Object, j As Long, n As Long
Set fL = CreateObject("Scripting.FileSystemObject")

saydır = saydır + 1
klasor2(saydır) = yol
sonraki:
For Each f In fL.getfolder(yol).subfolders
Liste (f.Path)
On Error GoTo sonraki
Next

End Sub
 
Paylaşımınız ve emeğiniz için en içten teşekkürlerimi, sevgi ve saygılarımı sunarım, sayın halit3.
 
Geri
Üst