Saving this code disables all macros on template?

AawwYeahh

New Member
Joined
Aug 10, 2017
Messages
37
I have used a previous version of this code to save file to a parent folder, but decided to modify it to save to more customer specific folder. BUT, if I try to save this work to my template then run, it somehow disables all macros links and does not give security messagebar to enable?????? (code still works in VBA window, but all GUI links say macros have been disabled...and no security warning messagebar at all)
VBA Code:
Sub GoogleContact()
Dim strFilename, strDirname, strPathname, strDefpath As String
On Error Resume Next
Worksheets("Dashboard").Select
strDirname = Range("A4").Value
strFilename = Range("A4").Value & "_Google"
strDefpath = "C:\MidSouth\PENDING\"
If IsEmpty(strDirname) Then Exit Sub
If IsEmpty(strFilename) Then Exit Sub

MkDir strDefpath & strDirname
strPathname = strDefpath & strDirname & "\" & strFilename
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
Sheets("Google").Copy 
  Application.DisplayAlerts = False
  With ActiveWorkbook
   .SaveAs filename:=strPathname, _
FileFormat:=xlCSV, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
End With
End Sub
 
Last edited:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Not related to your issue, but this line
VBA Code:
Dim strFilename, strDirname, strPathname, strDefpath As String
only declares strDefpath as a String, the rest as variants. You need to declare them this way:
VBA Code:
Dim strFilename As String, strDirname As String, strPathname As String, strDefpath As String

I'm not sure how to solve the issue, but there are some questions that might point you in the right direction.
What are your macro settings?
Is the template in a trusted location?
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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