Question:
i have an excel file and i want to open in in vb6 (Visual basic 6) AS "READ AND WRITE". please help?
R-den
2010-01-05 04:29:16 UTC
i used this and it works actually.. but it opens the excel file as "Read-only" i want it to open as read-and write so my vb6 program will be able to edit the contents in the cells and save it on click of a command button from my program. please help me.. :(

Dim xlTmp As Excel.Application
Set xlTmp = New Excel.Application
xlTmp.Workbooks.Open "MyXL.xls"
Three answers:
Maurizio
2010-01-05 04:49:45 UTC
First, add a reference to Microsft excel object library and then try this source code:





Option Explicit



Private Sub Command1_Click()

Dim xlTmp As Excel.Application

Dim wb As Workbook

Dim ws As Worksheet

Dim var As Variant



Set xlTmp = New Excel.Application



Set wb = xlTmp.Workbooks.Open("MyXL.xls")

'Specify your worksheet name

Set ws = wb.Worksheets("Sheet1")



'For READING CELL

var = ws.Range("B3").Value

'or

var = ws.Cells(2, 3).Value



'FOR WRITE CELL

ws.Cells(1, 1).Value = "My text"

ws.Cells(2, 1).Value = "1234.56"



wb.Close



'or ws.SaveAs("C:\\myDocument\myNewXL.xls")



xlApp.Quit

Set ws = Nothing

Set wb = Nothing

Set xlTmp = Nothing



End Sub
?
2016-10-06 16:56:00 UTC
The Open With determination is the only way. Make your application, acceptable click on it and decide Open With.. like different domicile windows data. you additionally can choose the comparable application to open all seen hardship-unfastened data utilising the comparable determination. in any different case, keep application as .exe
perisholisa
2010-01-05 04:34:14 UTC
i think you have to rename the file before you make it, go to your office button,, click save as, then rename it under something different, then make what you need to make.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...