09. december 2008 - 16:46Der er
6 kommentarer og 1 løsning
Gemme PP fil inde fra Excel
Flg kode bruges til at lave et dias ud fra et område i Excel. Jeg vil gerne have, at der skal poppe en dialogboksn op, som spørger om det aktuelle dias skal gemmes - vbYesNo. Ved ja skal save as komme frem med filplacering - "C\Dias fra excel". Filnavn skal brugeren selv skrive + dato sættes aut. til bagefter navn. Den nuværende kosde er:
Sub Dias() ' ' Range ' Application.Goto Reference:="Område i Excel" ' ' KopierTilBillede ' Selection.CopyPicture _ Appearance:=xlScreen, Format:=xlPicture Application.Goto Reference:="Område i Excel - lavet om til billede" ActiveSheet.Paste ' ' Billedstørrelse ' Selection.ShapeRange.LockAspectRatio = msoTrue Selection.ShapeRange.Height = 363.75 Selection.ShapeRange.Width = 682.5 Selection.ShapeRange.Rotation = 0# Selection.Copy ' ' OpretDias ' Dim PPApp As PowerPoint.Application Dim PPTPres As PowerPoint.Presentation Dim PPTSlide As PowerPoint.Slide
Set PPApp = CreateObject("Powerpoint.Application") Set PPTPres = PPApp.Presentations.Add PPApp.Visible = True PPApp.ActiveWindow.ViewType = ppViewSlide
With PPTPres.Slides Set PPTSlide = .Add(.Count + 1, ppLayoutText) End With Set PPTSlide = PPTPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) Selection.CopyPicture Appearance:=xlScreen, _ Format:=xlPicture
Sub Dias() ' ' Range ' Application.Goto Reference:="Område i excel" ' ' KopierTilBillede ' Selection.CopyPicture _ Appearance:=xlScreen, Format:=xlPicture Application.Goto Reference:="Område i Excel" ActiveSheet.Paste ' ' Billedstørrelse ' Selection.ShapeRange.LockAspectRatio = msoTrue Selection.ShapeRange.Height = 363.75 Selection.ShapeRange.Width = 682.5 Selection.ShapeRange.Rotation = 0# Selection.Copy ' ' OpretDias ' Dim PPApp As PowerPoint.Application Dim PPTPres As PowerPoint.Presentation Dim PPTSlide As PowerPoint.Slide Dim strFILNAVN As String Dim strHDMAPPE As String
strHDMAPPE = "C:\"
Set PPApp = CreateObject("Powerpoint.Application") Set PPTPres = PPApp.Presentations.Add PPApp.Visible = True PPApp.ActiveWindow.ViewType = ppViewSlide
With PPTPres.Slides Set PPTSlide = .Add(.Count + 1, ppLayoutText) End With Set PPTSlide = PPTPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) Selection.CopyPicture Appearance:=xlScreen, _ Format:=xlPicture
gem = MsgBox("Skal dias gemmes", vbYesNo, "Skal dias gemmes") If gem = 6 Then FILNAVN = InputBox("Gem Dias som:", "Gem Dias") PPApp.ActivePresentation.SaveAs Filename:=strHDMAPPE & FILNAVN & " " & Date Else End If
Set PPTSlide = Nothing Set PPTPres = Nothing Set PPApp = Nothing Selection.Delete 'Område i Excel - lavet om til billede, fernes'
Det ser ud til at virke - nej, det virker, men dialogboksene åbner op i excel, hvilket ikke er så godt,da man står i pp (har muligvis forklaret mig lidt for kryptisk). Hvad nu hvis man gemmer fil med samme navn, samme dag - kunne man evt sætte klokkeslet på, så bliver de i hvert tilfælde unikke - øh hvordan. strHDMAPPE & FILNAVN & " " & Date & " " & ??????
Jeg har fundet ud af og sætte en skabelon ind, samt løst problemet med dialogboksene. Det er fint nok, at stå inde i Excel og besvare boksene, da diasbillede er taget der. Så snart man har gemt filen, går man tilbage til PowerPoint. Når man lukker der, går man så tilbage til excel.
Tilbage er der så... Når jeg sætter "Now" ind får jeg en fejl:Presentation (Unknown member): Der opstod en fejl, mens PowerPoint gemte filen.
Sub Dias2() ' ' Range ' Application.Goto Reference:="Område1 i Excel" ' ' KopierTilBillede ' Selection.CopyPicture _ Appearance:=xlScreen, Format:=xlPicture Application.Goto Reference:="Område2 i Excel - paste billede" ActiveSheet.Paste ' ' Billedstørrelse ' Selection.ShapeRange.LockAspectRatio = msoTrue Selection.ShapeRange.Height = 363.75 Selection.ShapeRange.Width = 682.5 Selection.ShapeRange.Rotation = 0# Selection.Copy ' ' OpretDias ' Dim PPApp As PowerPoint.Application Dim PPTPres As PowerPoint.Presentation Dim PPTSlide As PowerPoint.Slide Dim strFILNAVN As String Dim strHDMAPPE As String
strHDMAPPE = "K:\Kundebesøg på genbrugsstationer (Datalog)\Excel dataudtræk\Testfiler\"
Set PPApp = CreateObject("Powerpoint.Application") Set PPTPres = PPApp.Presentations.Add PPApp.Visible = True PPApp.ActiveWindow.ViewType = ppViewSlide
With PPTPres.Slides Set PPTSlide = .Add(.Count + 1, ppLayoutText) End With PPApp.ActivePresentation.ApplyTemplate Filename:="c:\Min fil PowerPoint.ppt" Set PPTSlide = PPTPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) Selection.CopyPicture Appearance:=xlScreen, _ Format:=xlPicture
gem = MsgBox("Skal dias gemmes?.", vbYesNo, "Skal dias gemmes?") If gem = 6 Then FILNAVN = InputBox("Gem Dias som:", "Gem Dias") PPApp.ActivePresentation.SaveAs Filename:=strHDMAPPE & FILNAVN & " " & Date Else End If
PPApp.Activate Set PPTSlide = Nothing Set PPTPres = Nothing Set PPApp = Nothing Selection.Delete 'Område i Excel - pastebillede, fjernes' Application.Goto Reference:="Poul"
Hej Jeg har leget med min tidligere kode. Fejlen i "Now" opstod naturligvis, da man ikke kan gemme filer med ":" i filnavnet.
Jeg har bare lavet en dato string med andet format.
Sub Dias() ' ' Range ' Application.Goto Reference:=Range("a1") ' KopierTilBillede ' Selection.CopyPicture _ Appearance:=xlScreen, Format:=xlPicture Application.Goto Reference:=Range("a1") ActiveSheet.Paste ' ' Billedstørrelse ' Selection.ShapeRange.LockAspectRatio = msoTrue Selection.ShapeRange.Height = 363.75 Selection.ShapeRange.Width = 682.5 Selection.ShapeRange.Rotation = 0# Selection.Copy ' ' OpretDias ' Dim PPApp As PowerPoint.Application Dim PPTPres As PowerPoint.Presentation Dim PPTSlide As PowerPoint.Slide Dim strFILNAVN As String Dim strHDMAPPE As String Dim strdato As String
Set PPApp = CreateObject("Powerpoint.Application") Set PPTPres = PPApp.Presentations.Add PPApp.Visible = True PPApp.ActiveWindow.ViewType = ppViewSlide
With PPTPres.Slides Set PPTSlide = .Add(.Count + 1, ppLayoutText) End With Set PPTSlide = PPTPres.Slides(PPApp.ActiveWindow.Selection.SlideRange.SlideIndex) Selection.CopyPicture Appearance:=xlScreen, _ Format:=xlPicture
gem = MsgBox("Skal dias gemmes", vbYesNo, "Skal dias gemmes") If gem = 6 Then strFILNAVN = InputBox("Gem Dias som:", "Gem Dias") PPApp.ActivePresentation.SaveAs Filename:=strHDMAPPE & strFILNAVN & " " & strdato Else End If
Set PPTSlide = Nothing Set PPTPres = Nothing Set PPApp = Nothing Selection.Delete 'Område i Excel - lavet om til billede, fernes'
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.