excel_learnerz

Board Regular
Joined
Dec 12, 2018
Messages
73
Hello all,

I was hoping one of the knowledgeable people here might want to lend some wisdom to help me with my macro

The below macro does work (I am new to VBA so apologies in advance for the bad code, I am sure there are nicer ways to write it)

the macro picks up a value and whichever currency it is it saves a sheet called "quote" to sharepoint in a folder with company name

That's all well and good but in the folder path I have "C:\users\user_1" as part of it. I have SP mapped to my network so the macro works for me since I am user_1 but how can I change this to get it to work for anyone who opens the workbook to generate a quote and not just me, I am not sure how the SP url, I tried but it didn't work or some other way

Thanks in advance


Sub Quote_SP()
Dim FSO
Dim USDFolder As String
Dim EURFolder As String
Dim UKFolder As String
Dim USDPath As String
Dim EURPath As String
Dim UKPath As String

USDPath = "C:\Users\user_1\company\Sales Team - Documents\Quotes\Test_USD"
EURPath = "C:\Users\user_1\company\Sales Team - Documents\Quotes\Test_EUR"
UKPath = "C:\Users\user_1\company\Sales Team - Documents\Quotes\Test_UK"
USDFolder = USDPath & ActiveSheet.Range("B2").Value
EURFolder = EURPath & ActiveSheet.Range("B2").Value
UKFolder = UKPath & ActiveSheet.Range("B2").Value
ChDir "C:\Users\user_1\company\Sales Team - Documents\Quotes"

If ActiveSheet.Range("B3").Value = "$ Dollar" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(USDFolder) Then
FSO.CreateFolder (USDFolder)
End If

With Sheets("Quote")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=USDFolder & "" & ActiveSheet.Range("B2").Value & " " & Format(Now, "mmm-dd-yyyy hh-mm") & " " & ActiveSheet.Range("B14").Value & " Quote.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False

End With
ElseIf ActiveSheet.Range("B3").Value = "£ Sterling" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(UKFolder) Then
FSO.CreateFolder (UKFolder)
End If
With Sheets("Quote")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=UKFolder & "" & ActiveSheet.Range("B2").Value & " " & Format(Now, "mmm-dd-yyyy hh-mm") & " " & ActiveSheet.Range("B14").Value & " Quote.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
ElseIf ActiveSheet.Range("B3").Value = "€ Euro" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(EURFolder) Then
FSO.CreateFolder (EURFolder)
End If
With Sheets("Quote")
.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=EURFolder & "" & ActiveSheet.Range("B2").Value & " " & Format(Now, "mmm-dd-yyyy hh-mm") & " " & ActiveSheet.Range("B14").Value & " Quote.pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End With
End If
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Please use
Code:
 tags when pasting code.

[CODE][COLOR=#303336][FONT=inherit]Environ[/FONT][/COLOR][COLOR=#303336][FONT=inherit]([/FONT][/COLOR][COLOR=#7D2727][FONT=inherit]"Username"[/FONT][/COLOR][COLOR=#303336][FONT=inherit])[/FONT][/COLOR]
This returns the username of whoever is logged into the Windows machine.
 
Upvote 0
wow cool thanks for that, but in the above where would I put that in?
thanks by the way

(sorry for not using code tags)
 
Upvote 0
Code:
UserName = [COLOR=#303336]Environ[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"Username"[/COLOR][COLOR=#303336])[/COLOR]
[COLOR=#333333]ChDir "C:\Users\" & UserName & "\company\Sales Team - Documents\Quotes"[/COLOR]
[COLOR=#333333]USDPath = ChDir & "\Test_USD"[/COLOR]
[COLOR=#333333]EURPath = [/COLOR][COLOR=#333333]ChDir & "[/COLOR][COLOR=#333333]\Quotes\Test_EUR"[/COLOR]
[COLOR=#333333]UKPath = [/COLOR][COLOR=#333333]ChDir & "[/COLOR][COLOR=#333333]\Test_UK"[/COLOR]
[COLOR=#333333]USDFolder = USDPath & ActiveSheet.Range("B2").Value[/COLOR]
[COLOR=#333333]EURFolder = EURPath & ActiveSheet.Range("B2").Value[/COLOR]
[COLOR=#333333]UKFolder = UKPath & ActiveSheet.Range("B2").Value[/COLOR][COLOR=#333333]
[/COLOR]

This would do the trick.

I would recommend not referring to active x's, nor selecting ranges. This is prone to return errors. A safer way:

Code:
sht = "Sheet name here"

With Workbooks("NAME")
'...
UKFolder = UKPath & .Sheets(sht).Range("B2").Value
'...
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,004
Messages
6,122,659
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top