How to call a function in sub which contains WriteLine??

saratchandra

New Member
Joined
Mar 16, 2018
Messages
6
Hi,

I am writing VBA script to generate JSON file from excel which contains the data in excel sheet.

I initialized the below function in VBA. But when I try to call the function i am getting error in WriteLine. Without WriteLine I am able to call the function.

Do I have to declare anything to call the function in Sub. I tried all the methods to make it work. But i am not able to do that.

Public Function Get_Datatype_String(my_s As String) As String
If (my_s = "DCI_DTYPE_BOOL") Then
Get_Datatype_String = "DCI_BOOL"
BLE_DCI_JSON.WriteLine(" Get_Datatype_String")
End If
End Function

Please help me in solving the issue.

Thanks & Regards,
Sarath.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
What's the error?

What is BLE_DCI_JSON and where have you declared/set it?

PS Why is the variable Get_DataType_String in quotes?
 
Upvote 0
Hi Norie,

I am getting the below error.

Run time Error:424
Object Required.

file_path = ActiveWorkbook.Path & "" & Cells(6, 3).value
Set BLE_DCI_JSON = fs.CreateTextFile(file_path, True)

I have given the path in excel sheet to create and save JSON file in folder. I am writing VBA script to generate .JSON file that contains data in excel sheet. The above file_path will contain the path to save JSON file. BLE is the name of our module which is Bluetooth. DCI is excel sheet name and JSON is the file format.

BLE_DCI_JSON.WriteLine(" Get_Datatype_String")

It indicates that i am writing the string which is in double quotes to the file which has to be generated when you click on button that is created in excel sheet.
If you click on that button it will execute the code and files will be generated.

Thanks & Regards,
Sarath.
 
Upvote 0
Where is BLE_DCI_JSON declared?

Do you actually want to write the exact string 'Get_Datatype_String' to BLE_DCI_JSON?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,999
Members
448,543
Latest member
MartinLarkin

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