如何在vb6中阅读当前工作表 [英] How to read current worksheet in vb6

查看:151
本文介绍了如何在vb6中阅读当前工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您需要有关在VB6中阅读当前工作表的帮助。目前它正在读取总文件并转移到二进制文件。但是我只需要发送当前的工作表。



我尝试了什么:



 私有 功能 pvGetFileAsMultipart(filePath  As   String ,sFileName  As   String ,boundary  As   String 正如 字节()
Dim nFile 作为 整数
Dim sPostData 作为 字符串
' ---读取文件
nFile = FreeFile
打开(filePath + \ + sFileName)对于二进制访问读取作为 nFile
如果 LOF(nFile)> 0 然后
ReDim baBuffer ( 0 LOF(nFile) - 1 作为 字节
获取 nFile ,, baBuffer
sPostData = StrConv(baBuffer,vbUnicode)
结束 如果
关闭nFile
' --- prepare body
sPostData = - &边界与vbCrLf& _
Content-Disposition:form-data; name = + sFileName + ; filename =& sFileName& & vbCrLf& _
Content-Type:application / octet-stream& vbCrLf& vbCrLf& _
sPostData& vbCrLf& _
- &边界与 -
' --- post
pvGetFileAsMultipart = StrConv(sPostData,vbFromUnicode)
End 功能

解决方案

你不能!



Excel文件结构为:工作簿 - >工作表集合

请参阅:工作簿对象(Excel) [ ^ ]



能够发送当前工作表,您需要将该工作表的副本保存到新工作簿中,然后将其另存为新工作簿:

 ThisWorkbook.ActiveSheet.Copy 
ActiveWorkbook。另存为 驱动器:\ Path \ newName.xslx
ActiveWorkbook.Close





现在,您可以使用该工作簿并将其完整路径传递给您的功能。



有关详细信息,请参阅:

如何:以编程方式打开工作簿 [ ^ ]

如何:以编程方式复制工作表 [ ^ ]

如何:以编程方式关闭工作簿 [ ^ ]


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:

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

解决方案

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:

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[^]


这篇关于如何在vb6中阅读当前工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆