How to save workbook in different folders depending on country code

hanz753

Board Regular
Joined
Aug 9, 2017
Messages
53
Hello,

I have the below code, I have nearly completed what I am trying to do. The final stage would be to save each workbook into different folders depending on the country code. Can you please help?




Private Sub filename_cellvalue()


Dim Path As String
Dim filename As String
Dim filename2 As String
'Dim country As String


Path = ""
filename = Range("A1")
filename2 = Range("B1")


ActiveWorkbook.SaveAs filename:=Path & filename & filename2 & ".xls", FileFormat:=xlNormal
End Sub
 
Sorry to bother you, I am not sure What I am missing.


Private Sub filename_cellvalue()




Dim CountryID As Variant
Dim PathRef As Variant
Dim LBcid As Long
Dim UBcid As Long
Dim LBpr As Long
Dim UBpr As Long
Dim FixPath As String
FixedPath = "C:\Documents\Countries"


CountryID = Array("GB", "FS", "DE", "NO", "SE")
PathRef = Array("UK \Hanz UK", "France\ Hanz France", "Germany \ Hanz Germany", "Denmark\Hanz Denmark", "Denmark\Hanz Denmark","Denmark\Hanz Denmark")




LBcid = LBound(CountryID)
UBcid = UBound(CountryID)
LBpr = LBound(PathRef)
UBpr = UBound(PathRef)




If UBcid = UBpr Then
Range("A1").Value = CountryID(0)
Range("A2").Value = CountryID(1)
Range("A3").Value = CountryID(2)
Range("B1").Value = PathRef(0)
Range("B2").Value = PathRef(1)
Range("B3").Value = PathRef(2)

End If


End Sub
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This is the code I am using it doesn't seem to be saving in the correct folder. It saves in the file in Documents.

Private Sub filename_cellvalue()


Dim Path As String
Dim filename As String
Dim filename2 As String
Dim country As String




filename = Range("A1")
filename2 = Range("B1")
country = Range("C1")


If country = GB Then
Path = Path = "C:\ Documents \ Countries \ UK \Hanz UK"
ElseIf country = DE Then
Path = Path = "C:\ Documents \ Countries \ Germany \ Hanz Germany"
ElseIf country = FS Then
Path = Path = "C:\ Documents \ Countries \ Germany \ Hanz France"
ElseIf country = NO Then
Path = Path = "C:\ Documents \ Countries \ Germany \ Hanz Norway"
ElseIf country = SE Then
Path = Path = "C:\ Documents \ Countries \ Germany \ Hanz Sweden"
End If




ActiveWorkbook.SaveAs filename:=Path & filename & filename2 & ".xls", FileFormat:=xlNormal




End Sub

Make sure your path ends in ""
IE Path = Path = "C:\ Documents \ Countries \ Germany \ Hanz Sweden\"
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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