Daugaard92
New Member
- Joined
- Nov 20, 2020
- Messages
- 17
- Office Version
- 2016
- Platform
- Windows
Hello everyone,
My VBA knowledge is unfortunately very limited and therefore, I have to seek advice. I hope I'm asking in the proper fashion and in accordance with forum regulation - Otherwise I sincerely apologise.
I haven't developed the following code - I'm just trying to figure out why it isn't working - I've discovered that most of the code, is directly copy/pasted from "Contextures.com". I have refrained from including the link, as I don't know whether or not I'm allowed to in a post.
From examining the code, I believe that the error lies with this top section. From the "Columns"-section" to the variable declearation. The purpose of this section (I think) is to select a dynamic print-range within the B-column in the sheet, as the print range change. I'm however not skilled enough with VBA to determine why it isn't working. Should a kind soul be able to determine what is wrong, I'd be grateful - And please keep an explanation simple, as I'm very new to VBA
My VBA knowledge is unfortunately very limited and therefore, I have to seek advice. I hope I'm asking in the proper fashion and in accordance with forum regulation - Otherwise I sincerely apologise.
I haven't developed the following code - I'm just trying to figure out why it isn't working - I've discovered that most of the code, is directly copy/pasted from "Contextures.com". I have refrained from including the link, as I don't know whether or not I'm allowed to in a post.
From examining the code, I believe that the error lies with this top section. From the "Columns"-section" to the variable declearation. The purpose of this section (I think) is to select a dynamic print-range within the B-column in the sheet, as the print range change. I'm however not skilled enough with VBA to determine why it isn't working. Should a kind soul be able to determine what is wrong, I'd be grateful - And please keep an explanation simple, as I'm very new to VBA
VBA Code:
Sub pdf()
Columns("B:B").Select
Selection.Find(What:="stop", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
Rrow = ActiveCell.Row
Range("B1" & ":" & "J" & Rrow + 2).Select
Dim wsA As Worksheet
Dim wbA As Workbook
Dim strTime As String
Dim strName As String
Dim strPath As String
Dim strFile As String
Dim strPathFile As String
Dim myFile As Variant
On Error GoTo errHandler
Set wbA = ActiveWorkbook
Set wsA = ActiveSheet
strTime = Format(Now(), "ddmmyyyy\_hhmm")
'get active workbook folder, if saved
strPath = wbA.Path
If strPath = "" Then
strPath = Application.DefaultFilePath
End If
strPath = strPath & "\"
'create default name for savng file
strFile = strName & "Tilbuds_tool_" & strTime & ".pdf"
strPathFile = strPath & strFile
'use can enter name and
' select folder for file
myFile = Application.GetSaveAsFilename _
(InitialFileName:=strPathFile, _
FileFilter:="PDF Files (*.pdf), *.pdf", _
Title:="Select Folder and File Name to save")
'export to PDF if a folder was selected
If myFile <> "False" Then
wsA.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=myFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
'confirmation message with file info
MsgBox "PDF file has been created: " _
& vbCrLf _
& myFile
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not create PDF file"
Resume exitHandler
End Sub