15. august 2017 - 08:20
Der er
28 kommentarer og 2 løsninger
ExportAsFixedFormat - Der opstod en kompileringsfejl: Der er en syntaksfejl
Hej Jeg har indsat en knap i excel med flg. makro: Sub GemPDF() ActiveWindow.ExportAsFixedFormat Type:=xlTypePDF FileName:="DV.pdf" Quality:=xlQualityStandard DisplayFileAfterPublish:=True End Sub , som gerne skulle gemme som pdf, men jeg får denne fejl: "Der opstod en kompileringsfejl: Der er en syntaksfejl" Kan I fortælle, hvad der er galt? Vh CHC
Annonceindlæg fra COMM2IG
15. august 2017 - 09:11
#2
Hi Terry Thanks for replying. I already tried that solution, it didn't help. Kind regards CHC
15. august 2017 - 09:59
#3
syntax errer betyder at det du har skrevet ikke er syntaktisk korrekt - med andre ord ikke vba. Teksten plejer at blive rød, så man ved den er gal. (jeg kender heller ikke excel) Nuvel - parameterlister er kommaseparerede sub something(number,message) ' end sub sub useit() something number:=1, message:="hej du" end sub
15. august 2017 - 10:40
#4
Hej bvirk Tak for indsatsen, men...det løste ikke min udfordring. Kort sagt, så skal jeg have en fane i excel gemt som pdf. Vh CHC
15. august 2017 - 10:48
#5
"syntax errer betyder at det du har skrevet ikke er syntaktisk korrekt " well that's what I originally thought but comparing the example at the bottom of the link I gave there is almost no difference other than activeworkbook Although of course examples can also be wrong ;-)
15. august 2017 - 10:49
#6
did you notice this in link I gave? "Note An error will occur if the PDF add-in is not currently installed."
15. august 2017 - 11:01
#7
Hej Terry Har herefter msdn kommenteret på eksemplet i linket - så må vi om der er nogen der læser disse høfligt anderkende feedbacks og smider nogle kommaer ind.
Synes godt om
1 synes godt om dette
15. august 2017 - 11:07
#8
Iøvrigt har jeg tit, efter at have lært meget mere af en fejl i bøger og online end den korrekte tekst ville have bidraget med; tænkt - gad vide om det er med vilje?
15. august 2017 - 11:07
#9
Hi terry I noticed the link and I've got Adobe Reader installed om my Mac, so I guess that should do it or...? Do I need anything special, when it says PDF add-in? CHC
15. august 2017 - 11:39
#11
but as bvirk correctly mentions, you need , in between your parameters ActiveWindow.ExportAsFixedFormat Type:=xlTypePDF, Filename:="DV.pdf", Quality:=xlQualityStandard, DisplayFileAfterPublish:=True
15. august 2017 - 12:00
#12
klippet fra msdn linket: ' Syntax expression . ExportAsFixedFormat( Type , Filename , Quality , IncludeDocProperties , IgnorePrintAreas , From , To , OpenAfterPublish , FixedFormatExtClassPtr ) expression A variable that represents a Workbook , Sheet , Chart , or Range object. ' Så kan man vel heller ikke bruge et activewindow object - hvad med et range object i stedet for - det er vel også en fane
15. august 2017 - 12:07
#13
Prøv: ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:="DV.pdf", _ Quality:=xlQualityStandard, _ OpenAfterPublish:=True
15. august 2017 - 12:46
#14
Tak til alle for forsøgene. @store-morten: jeg får en "fejl under udskrivning" og efter følgende en "Fejl på kørselstidspunktet: '1004': Fejl i program eller objekt" Vh CHC
15. august 2017 - 13:43
#15
If you compile the code (under debug menu) you will get an error if you use ActiveWindow.ExportAsFixedFormat Type:=xlTypePDF, Filename:="DV.pdf", Quality:=xlQualityStandard, DisplayFileAfterPublish:=True but if you comment out or remove the last parameter then compile you dont get an error and you should be able to create the file.
15. august 2017 - 13:44
#16
sorry, use activeworkbook With error: ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="DV.pdf", Quality:=xlQualityStandard, DisplayFileAfterPublish:=True Without error: ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="c:\data\DV.pdf", Quality:=xlQualityStandard ', DisplayFileAfterPublish:=True
15. august 2017 - 13:47
#17
change last parameter to OpenAfterPublish instead of DisplayFileAfterPublish and it may work
15. august 2017 - 13:49
#18
so you end up with Sub GemPDF() ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="DV.pdf", Quality:=xlQualityStandard, openAfterPublish:=True End Sub
15. august 2017 - 14:12
#19
Hi Terry It says "Fejl under udskrivning" ("error when writing") and "Fejl på kørselstidspunktet: '1004': Der opstod fejl i metoden 'ExportAsFixedFormat' for objektet '_Workbook'" Does it make any sense?
15. august 2017 - 14:29
#20
"Does it make any sense? " No, not really :-( I can copy and paste the code Sub GemPDF() ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, Filename:="DV.pdf", Quality:=xlQualityStandard, openAfterPublish:=True End Sub into any Excel file with a workbook and it works. And I can see that I have any add-ins for PDF. I'm using Office 2013 if that makes any difference.
15. august 2017 - 14:32
#21
I dont have any add-ins for pdf
15. august 2017 - 14:55
#22
Disse 2 virker hos mig, bruger Excel 2013
Sub Gem_aktive_ark_som_PDF() ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:="DV.pdf", _ Quality:=xlQualityStandard, _ openAfterPublish:=True End Sub
Sub Gem_alle_ark_som_PDF() ActiveWorkbook.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:="DV.pdf", _ Quality:=xlQualityStandard, _ openAfterPublish:=True End Sub
15. august 2017 - 15:10
#23
Makro optager giver:
Sub Makro1() ' ' Makro optager ' ' ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _ "C:\Users\CHC \Desktop\DV.pdf", Quality:=xlQualityStandard, _ IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _ True End Sub
CHC skal til rettes til det du er oprette med i Excel.
Så gemmes PDF filen på: Skrivebordet
15. august 2017 - 15:41
#24
@Terry: This is strange. It didn't work at first, then it worked once, and now it doesn't work. I tried it on a Lenovo and it works, so it must be a bug on my Mac. @Store-morten: Jeg kan ikke få det til at virke på min Mac, men de to første løsninger virker på en Lenovo. Any solutions?
15. august 2017 - 15:43
#25
"Fejl under udskrivning" ("error when writing") and "Fejl på kørselstidspunktet: '1004': Der opstod fejl i metoden 'ExportAsFixedFormat' for objektet '_Workbook'"
15. august 2017 - 16:26
#26
So it is working in Office on a windows PC but not with your mac? Solution: Throw the mac out :-) well I cant help with anything to do with mac/apple as I never have and never will have one ;-)
Synes godt om
1 synes godt om dette
16. august 2017 - 07:17
#27
I've read that Microsoft has made some changes since the Office 2013, which means some functions are not working. :-( Thanks everyone for your support. CHC
16. august 2017 - 09:11
#28
I assume that's on your MAC, I very much doubt they would make changes to vba functions just because they release newer versions of Office. og selv tak
16. august 2017 - 09:49
#29
16. august 2017 - 10:41
#30
I hope so too ;-)
Kurser inden for grundlæggende programmering