<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Dansk Regneark Forum : gem som med filnavn fra celle A1</title>
  <link>https://forum.excel-regneark.dk/</link>
  <description><![CDATA[Dette er et XML Feed af; Dansk Regneark Forum : Makro og VBA : gem som med filnavn fra celle A1]]></description>
  <pubDate>Sat, 05 Dec 2026 13:30:20 +0000</pubDate>
  <lastBuildDate>Mon, 15 Oct 2018 10:47:52 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.08</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>https://forum.excel-regneark.dk/RSS_post_feed.asp?TID=3644</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Dansk Regneark Forum]]></title>
   <url>https://forum.excel-regneark.dk/css_styles/Excel-regneark.dk/logo.png</url>
   <link>https://forum.excel-regneark.dk/</link>
  </image>
  <item>
   <title><![CDATA[gem som med filnavn fra celle A1 : hej alle jeg &#248;nsker at lave en...]]></title>
   <link>https://forum.excel-regneark.dk/gem-som-med-filnavn-fra-celle-a1_topic3644_post17998.html#17998</link>
   <description>
    <![CDATA[<strong>Forfatter:</strong> <a href="https://forum.excel-regneark.dk/member_profile.asp?PF=2316">MTE</a><br /><strong>Emne:</strong> 3644<br /><strong>Sendt:</strong> 15.Okt.2018 kl. 10:47<br /><br />hej alle jeg ønsker at lave en funktion der gemmer en kopi af mit ark stien skal være det der står i celle A1&nbsp;<div><br></div><div>derefter skal den lave en pdf fil og gemme den på en bestem sti med samme navn celle A1 og åben en mail med pdfen vedhæftet&nbsp;</div><div>mit problem er at det skal lægge på et fælles drev så mange kan tilgå det og det driller jeg har lavet følgende som virker på min pc men den vil ikke virke på de andres og har heller ikke fået den til at navngive efter celle A1&nbsp;</div><div>håber der er en der kan hjælpe&nbsp;</div><div><br></div><div><div>Sub RDB_Workbook_To_PDF_And_Create_Mail()</div><div>&nbsp; &nbsp; Dim FileName As String</div><div><br></div><div>&nbsp; &nbsp; 'Call the function with the correct arguments</div><div>&nbsp; &nbsp; FileName = RDB_Create_PDF(Source:=ActiveWorkbook, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FixedFilePathName:="", _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OverwriteIfFileExist:=True, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenPDFAfterPublish:=False)</div><div><br></div><div>&nbsp; &nbsp; 'For a fixed file name use this in the FixedFilePathName argument</div><div>&nbsp; &nbsp; 'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"</div><div><br></div><div>&nbsp; &nbsp; If FileName &lt;&gt; "" Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrTo:="JDG@energinet.dk;netvagt@energinet.dk;sss@energinet.dk", _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrCC:="", _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrBCC:="", _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrSubject:="This is the subject", _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Signature:=True, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Send:=False, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StrBody:="&lt;H3&gt;&lt;B&gt;Resultat af testen&lt;/B&gt;&lt;/H3&gt;&lt;br&gt;" &amp; _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;body&gt;test af nettelegraf."</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; Else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; MsgBox "Not possible to create the PDF, possible reasons:" &amp; vbNewLine &amp; _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"Microsoft Add-in is not installed" &amp; vbNewLine &amp; _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"You Canceled the GetSaveAsFilename dialog" &amp; vbNewLine &amp; _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"The path to Save the file in arg 2 is not correct" &amp; vbNewLine &amp; _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"You didn't want to overwrite the existing PDF if it exist"</div><div>&nbsp; &nbsp; End If</div><div>End Sub</div><div><br></div><div>Function RDB_Create_PDF(Source As Object, FixedFilePathName As String, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OverwriteIfFileExist As Boolean, OpenPDFAfterPublish As Boolean) As String</div><div>&nbsp; &nbsp; Dim FileFormatstr As String</div><div>&nbsp; &nbsp; Dim Fname As Variant</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; If FixedFilePathName = "" Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Open the GetSaveAsFilename dialog to enter a file name for the pdf</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileFormatstr = "PDF Files (*.pdf), *.pdf"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Title:="Create PDF")</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If you cancel this dialog Exit the function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If Fname = False Then Exit Function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fname = FixedFilePathName</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'If OverwriteIfFileExist = False we test if the PDF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'already exist in the folder and Exit the function if that is True</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If OverwriteIfFileExist = False Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If Dir(Fname) &lt;&gt; "" Then Exit Function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'Now the file name is correct we Publish to PDF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; On Error Resume Next</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Source.ExportAsFixedFormat _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Type:=xlTypePDF, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileName:=Fname, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Quality:=xlQualityStandard, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IncludeDocProperties:=True, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IgnorePrintAreas:=False, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenAfterPublish:=OpenPDFAfterPublish</div><div>&nbsp; &nbsp; &nbsp; &nbsp; On Error GoTo 0</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'If Publish is Ok the function will return the file name</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If Dir(Fname) &lt;&gt; "" Then RDB_Create_PDF = Fname</div><div>End Function</div><div><br></div><div><br></div><div><br></div><div>Function RDB_Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StrCC As String, StrBCC As String, StrSubject As String, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Signature As Boolean, Send As Boolean, StrBody As String)</div><div>&nbsp; &nbsp; Dim OutApp As Object</div><div>&nbsp; &nbsp; Dim OutMail As Object</div><div><br></div><div>&nbsp; &nbsp; Set OutApp = CreateObject("Outlook.Application")</div><div>&nbsp; &nbsp; Set OutMail = OutApp.CreateItem(0)</div><div><br></div><div>&nbsp; &nbsp; On Error Resume Next</div><div>&nbsp; &nbsp; With OutMail</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If Signature = True Then .Display</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .To = StrTo</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .CC = StrCC</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .BCC = StrBCC</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .Subject = StrSubject</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .HTMLBody = StrBody &amp; "&lt;br&gt;" &amp; .HTMLBody</div><div>&nbsp; &nbsp; &nbsp; &nbsp; .Attachments.Add FileNamePDF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If Send = True Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Send</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .Display</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div>&nbsp; &nbsp; End With</div><div>&nbsp; &nbsp; On Error GoTo 0</div><div><br></div><div>&nbsp; &nbsp; Set OutMail = Nothing</div><div>&nbsp; &nbsp; Set OutApp = Nothing</div><div>End Function</div><div><br></div><div><br></div><div><br></div><div>Function Create_PDF_Sheet_Level_Names(NamedRange As String, FixedFilePathName As String, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OverwriteIfFileExist As Boolean, OpenPDFAfterPublish As Boolean) As String</div><div>'This function will create a PDF with every sheet with</div><div>'a sheet level name variable &lt;NamedRange&gt; in it</div><div>&nbsp; &nbsp; Dim FileFormatstr As String</div><div>&nbsp; &nbsp; Dim Fname As Variant</div><div>&nbsp; &nbsp; Dim Ash As Worksheet</div><div>&nbsp; &nbsp; Dim sh As Worksheet</div><div>&nbsp; &nbsp; Dim ShArr() As String</div><div>&nbsp; &nbsp; Dim s As Long</div><div>&nbsp; &nbsp; Dim SheetLevelName As Name</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'We fill the Array with sheets with the sheet level name variable</div><div>&nbsp; &nbsp; &nbsp; &nbsp; For Each sh In ActiveWorkbook.Worksheets</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If sh.Visible = -1 Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set SheetLevelName = Nothing</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; On Error Resume Next</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Set SheetLevelName = sh.Names(NamedRange)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; On Error GoTo 0</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If Not SheetLevelName Is Nothing Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s = s + 1</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ReDim Preserve ShArr(1 To s)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShArr(s) = sh.Name</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; End If</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Next sh</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'We exit the function If there are no sheets with</div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'a sheet level name variable named &lt;NamedRange&gt;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If s = 0 Then Exit Function</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; If FixedFilePathName = "" Then</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Open the GetSaveAsFilename dialog to enter a file name for the pdf</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileFormatstr = "PDF Files (*.pdf), *.pdf"</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fname = Application.GetSaveAsFilename("", filefilter:=FileFormatstr, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Title:="Create PDF")</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'If you cancel this dialog Exit the function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If Fname = False Then Exit Function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Fname = FixedFilePathName</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'If OverwriteIfFileExist = False we test if the PDF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'already exist in the folder and Exit the function if that is True</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If OverwriteIfFileExist = False Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If Dir(Fname) &lt;&gt; "" Then Exit Function</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; Application.ScreenUpdating = False</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Application.EnableEvents = False</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'Remember the ActiveSheet</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Set Ash = ActiveSheet</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'Select the sheets with the sheet level name in it</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Sheets(ShArr).Select</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'Now the file name is correct we Publish to PDF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; On Error Resume Next</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ActiveSheet.ExportAsFixedFormat _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Type:=xlTypePDF, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileName:=Fname, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Quality:=xlQualityStandard, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IncludeDocProperties:=True, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IgnorePrintAreas:=False, _</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OpenAfterPublish:=OpenPDFAfterPublish</div><div>&nbsp; &nbsp; &nbsp; &nbsp; On Error GoTo 0</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; 'If Publish is Ok the function will return the file name</div><div>&nbsp; &nbsp; &nbsp; &nbsp; If Dir(Fname) &lt;&gt; "" Then</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Create_PDF_Sheet_Level_Names = Fname</div><div>&nbsp; &nbsp; &nbsp; &nbsp; End If</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; Ash.Select</div><div><br></div><div>&nbsp; &nbsp; &nbsp; &nbsp; Application.ScreenUpdating = True</div><div>&nbsp; &nbsp; &nbsp; &nbsp; Application.EnableEvents = True</div><div>End Function</div><div><br></div><div><br></div><div><br></div></div>]]>
   </description>
   <pubDate>Mon, 15 Oct 2018 10:47:52 +0000</pubDate>
   <guid isPermaLink="true">https://forum.excel-regneark.dk/gem-som-med-filnavn-fra-celle-a1_topic3644_post17998.html#17998</guid>
  </item> 
 </channel>
</rss>