Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi need help regarding reading current worksheet in VB6. Currently it is reading total file and moving to binary. But i need to send only current working sheet.

What I have tried:

VB
Private Function pvGetFileAsMultipart(filePath As String, sFileName As String, boundary As String) As Byte()
    Dim nFile As Integer
    Dim sPostData As String
     '--- read file
    nFile = FreeFile
     Open (filePath + "\" + sFileName) For Binary Access Read As nFile
    If LOF(nFile) > 0 Then
        ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
        Get nFile, , baBuffer
        sPostData = StrConv(baBuffer, vbUnicode)
    End If
    Close nFile
    '--- prepare body
    sPostData = "--" & boundary & vbCrLf & _
        "Content-Disposition: form-data; name=""" + sFileName + """; filename=""" & sFileName & """" & vbCrLf & _
        "Content-Type: application/octet-stream" & vbCrLf & vbCrLf & _
        sPostData & vbCrLf & _
        "--" & boundary & "--"
    '--- post
    pvGetFileAsMultipart = StrConv(sPostData, vbFromUnicode)
End Function
Posted
Updated 9-Sep-16 7:48am
v3
Comments
Maciej Los 9-Sep-16 13:24pm    
Could you be more specific and provide more details about what you're trying to achieve?
[no name] 9-Sep-16 13:30pm    
The main trick of asking a decent question is being clear. "Moving to binary" makes no sense. What does VB.NET have to do with this code? What is it that you need help with? "Send current working sheet", what is a working sheet? Send it where?
Maciej Los 9-Sep-16 13:33pm    
Send it to the Never-never-Land ;)
[no name] 9-Sep-16 13:40pm    
Ah... then we need a PeterPan method....
Maciej Los 9-Sep-16 13:48pm    
:laugh:

1 solution

You can't!

Excel file structure is: Workbook->Worksheets collection
See: Workbook Object (Excel)[^]

To be able to "send current worksheet", you need to save a copy of that sheet into new workbook, then save it as new workbook:
VB
ThisWorkbook.ActiveSheet.Copy
ActiveWorkbook.SaveAs "Drive:\Path\newName.xslx"
ActiveWorkbook.Close


Now, you can use that workbook and pass its full-path to your function.

For further details, please see:
How to: Programmatically Open Workbooks[^]
How to: Programmatically Copy Worksheets[^]
How to: Programmatically Close Workbooks[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900