VBA to upload Excel File to Sharepoint. Run Time error '1004'

Conell8383

Board Regular
Joined
Jul 26, 2016
Messages
66
Hi all I hope you can help. I have a piece of code and what it does is if cell A2 is changed to anything other than "Enter Your Country Here" it finds and replaces all the "Enter Your Country Here" in the workbook with the new value in A2. This part works fine. The issue I am having is that once the cell change happens I also want the workbook to save to our Sharepoint environment. But I keep getting Run Time error '1004' on the following line

Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#303336]SaveAs Filename[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]"http://teamspace.merck.com/sites/emea_efpia/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2Fsites%2Femea%5Fefpia%2FShared%20Documents%2FEFPIA%20Regional%20Reporting%20Team%2FDispute%20Management%2FDispute%20reports%20per%20market%2FGlobal%20Reporting&FolderCTID=0x012000FA7F4E9565D6274DAF9E871EA008299B&View=%7BB6EF0397-E24C-49DF-92EF-CB7015B60539"[/COLOR]</code>

If I replace the Sharepoint address with a C drive or local address it works perfectly. Am I missing something? Can my code be amended to allow the workbook to be saved to Sharepoint? My code is below and as always any and all help is greatly appreciated.
CODE


Code:
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">[COLOR=#101094]Private[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Sub[/COLOR][COLOR=#303336] Worksheet_Change[/COLOR][COLOR=#303336]([/COLOR][COLOR=#101094]ByVal[/COLOR][COLOR=#303336] Target [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]

  ThisFile [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A2"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Value
  [/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] cell [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Range
  [/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] sht [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] Worksheet
  [/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] fnd [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Variant[/COLOR][COLOR=#303336]
  [/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] rplc [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Variant[/COLOR][COLOR=#303336]

  fnd [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]"Enter Your Country Here"[/COLOR][COLOR=#303336]
  rplc [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Worksheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"SearchCasesResults"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A2"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Value
  [/COLOR][COLOR=#101094]For[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Each[/COLOR][COLOR=#303336] sht [/COLOR][COLOR=#101094]In[/COLOR][COLOR=#303336] ActiveWorkbook[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Worksheets
  sht[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Cells[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Replace what[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]fnd[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] Replacement[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]rplc[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] _
  LookAt[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]xlPart[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] SearchOrder[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#303336]xlByRows[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] MatchCase[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] _
  SearchFormat[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] ReplaceFormat[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]False[/COLOR][COLOR=#303336]
  [/COLOR][COLOR=#101094]Next[/COLOR][COLOR=#303336] sht
  [/COLOR][COLOR=#101094]For[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Each[/COLOR][COLOR=#303336] cell [/COLOR][COLOR=#101094]In[/COLOR][COLOR=#303336] Range[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"A2"[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
  [/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336] cell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]<>[/COLOR][COLOR=#303336] [/COLOR][COLOR=#7D2727]"Enter Your Country Here"[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Then[/COLOR][COLOR=#303336]
  SaveAs Filename[/COLOR][COLOR=#303336]:=[/COLOR][COLOR=#7D2727]"http://teamspace.merck.com/sites/emea_efpia/Shared%20Documents/Forms/AllItems.aspx?RootFolder=%2Fsites%2Femea%5Fefpia%2FShared%20Documents%2FEFPIA%20Regional%20Reporting%20Team%2FDispute%20Management%2FDispute%20reports%20per%20market%2FGlobal%20Reporting&FolderCTID=0x012000FA7F4E9565D6274DAF9E871EA008299B&View=%7BB6EF0397-E24C-49DF-92EF-CB7015B60539"[/COLOR][COLOR=#303336]
  [/COLOR][COLOR=#101094]End[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]If[/COLOR][COLOR=#303336]
  [/COLOR][COLOR=#101094]Next[/COLOR][COLOR=#303336] cell
  Worksheets[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]"SearchCasesResults"[/COLOR][COLOR=#303336]).[/COLOR][COLOR=#303336]Activate
  ActiveWorkbook[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Close

[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#303336] [/COLOR][COLOR=#101094]Sub[/COLOR]</code>
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,216,096
Messages
6,128,807
Members
449,468
Latest member
AGreen17

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