I get a permission denied error when I execute the code detailed.

get2noesks

New Member
Joined
Jul 15, 2015
Messages
24
Hi,

I am trying to create a notepad through VBA and when I execute these lines of code I get permission error. Any insights?

Private Sub Workbook_Open()
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile("C:\Users\u418558\Desktop\XML tool")
oFile.WriteLine "test"
oFile.Close
Set fso = Nothing
Set oFile = Nothing
End Sub

Regards
Saurabh
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Set oFile = fso.CreateTextFile("C:\Users\u418558\Desktop\XML tool.txt")

Possibly...?!
 
Upvote 0
not sure, but I think you need to include another reference to access filesystemobject? and another possibility, (again not sure) do you need the .txt in the filename?
 
Upvote 0
Tested the code you provided with a folder on my desktop and it works with and without the ".txt"
 
Upvote 0
Hi,

Working with .txt file extension. Thanks. Could someone explain the reason why did it not work without .txt extension?

Regards
Saurabh
 
Upvote 0
Because the code doesn't know what "XML tool" is until a filetype extension is used !
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,684
Members
449,116
Latest member
HypnoFant

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