Issues with thisworkbook.path

AndreasL

New Member
Joined
Dec 8, 2021
Messages
18
Office Version
  1. 365
Platform
  1. Windows
I've searched everywhere and I've tried using the tips I've come across, however I still run into isses using Thisworkbook.path.
This code works fine if I use $Environ(username), and put the path, but I'm not sure the other ones in my office has the onedrive folder saved in the same location.
It would then also only work if synced to PC, so I'm trying to work around this solution.
Turning off sync to cloud is not an option as there are several working with this sheet daily.

My code is as follows now, please help me locate the issue. (I get path/access error (75) even tho Thisworkbook.path works in other macros exporting PDF to folders in the same location).
It seems neither the Exportpath or the LoadPicture is working with this at the moment, but first of all I'm stuck with this line:

VBA Code:
.Export Filename:=Exportpath, FilterName:="bmp"

VBA Code:
 Set oWs = Ark3
 Set oRng = oWs.Range("A1:O36")
 Exportpath = ThisWorkbook.Path & "/" & "temp" & "/" & "PLAN.bmp"

 oRng.CopyPicture xlScreen, xlPicture
 lWidth = oRng.Width
 lHeight = oRng.Height
    Worksheets("PLAN").Unprotect
 Set oChrtO = oWs.ChartObjects.Add(Left:=0, Top:=0, Width:=lWidth, Height:=lHeight)

 oChrtO.Activate
 With oChrtO.Chart
  .Paste
  .Export Filename:=Exportpath, FilterName:="bmp"
 End With

 oChrtO.Delete
 
 IMGplanen.Picture = LoadPicture(ThisWorkbook.Path & "/" & "temp" & "/" & "PLAN.bmp")
 
Can i force it to remove a read only attribute in the VBA code? Or save as file that can be overwritten?
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The moment you create a new file and then save it (with a name that has not yet been used in that folder), that file by definition does NOT have the read-only attribute.
If there's already a file with the same name and it's having a read-only attribute, then there must be a reason for that so I would recommend not deleting or overwriting such a file unconditionally.
 
Upvote 0
The moment you create a new file and then save it (with a name that has not yet been used in that folder), that file by definition does NOT have the read-only attribute.
If there's already a file with the same name and it's having a read-only attribute, then there must be a reason for that so I would recommend not deleting or overwriting such a file unconditionally.
I’ve created the folder and all the files in it. The use of this is for weekly updating a production plan, so the old ones are not needed for future as they are logged in SAP and other systems for future reference.
Seems the issue is overwriting When using the SharePoint filepath then. Using Environ bypasses this.
It would make sense for them to not have vba macros overwrite stuff on the servers.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

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