Hente billede til word doc.
Word 2010Bruger flg. kode til at indsætte et billede i brevhovedet på et word doc.Den er noget sammensat, men funker. Dog er jeg stødt ind i det problem, at hvis man trykker på annuller i billedmappen, har den jo åbnet brevhovedet i doc., men får det ikke lukket - tror jeg nok. Man skulle vel først have billedet ind i en "streng, før man begynder, at bearbejde doc.
Jamen, så er spørgsmålet altså - hvordan?
Application.Run MacroName:="IkkeOpdateringAfSkærm"
'Speciel første side
With Selection.PageSetup
.DifferentFirstPageHeaderFooter = True
End With
'Find første side
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
'Slet evt gl. forsidebillede
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
'Sletter evt gl. forsidebillede
If ActiveDocument.Bookmarks.Exists("Forsidebillede") Then
ActiveDocument.Bookmarks("Forsidebillede").Select
Selection.Delete
End If
'Sletter evt LogoRD
If ActiveDocument.Bookmarks.Exists("LogoRD") Then
ActiveDocument.Bookmarks("LogoRD").Select
Selection.Delete
End If
'Sletter evt. LogoNederst
If ActiveDocument.Bookmarks.Exists("LogoNederstRD") Then
ActiveDocument.Bookmarks("LogoNederstRD").Select
Selection.Delete
End If
'Sletter evt. teksboks
If ActiveDocument.Bookmarks.Exists("Tekst") = True Then
'Kopierer udgangspunkt(font)
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"
Selection.TypeText Text:="1"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
ActiveDocument.Bookmarks("Tekst").Select
Selection.WholeStory
'Indsætter udgangstekst
Selection.PasteAndFormat (wdFormatOriginalFormatting)
'Sletter
Selection.ShapeRange.Select
Selection.Delete
Else
End If
'Sætter billedarkiv
Dim sPixFolder As String
''' store the default pictures location
sPixFolder = Options.DefaultFilePath(wdPicturesPath)
''' change the default pictures location
Options.DefaultFilePath(wdPicturesPath) = "C:\Users\pom\Pictures\"
''' open the dialog box
Dialogs(wdDialogInsertPicture).Show
''' restore the default pictures location
Options.DefaultFilePath(wdPicturesPath) = sPixFolder
'Marker billede
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Select
'Indsætte bogmærke
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="Forsidebillede"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'Ombryde/størrelse billede
Selection.ShapeRange.WrapFormat.Type = wdWrapNone
Selection.ShapeRange(1).LockAspectRatio = msoFalse
Selection.ShapeRange.Width = CentimetersToPoints(20.01)
Selection.ShapeRange.Height = CentimetersToPoints(28.69)
'Placering
With Selection.ShapeRange
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.Left = 14
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Top = 14
End With
'Lukker brevhoved
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Application.Run MacroName:="OpdaterSkærm"
