Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15685

Updating Excel Spreadsheet Issue

$
0
0
tl;dr: I'm trying to export data from certain Label.Captions into a spreadsheet by finding the next blank row/column and inputting the data automatically.

Hello all! I'm new to the forum and super stoked that others still use VB6. I realize there's new versions out, but VB6 is the one I used ~12 years ago in high school, and I haven't actually programmed since then and I'm REALLY out of touch. (Like, very out of touch. Required google to do the simplest tasks)

Okay, so here's the story. I'm making a program that assigns point values to different RPG stats for a board game I'm making. I want to export those results to an excel spreadsheet without overwriting the previous results. I'm doing it this way to just make it easier on myself when I use the spreadsheet & photoshop to export prototype cards.

I'm mostly getting Object Required errors and it's driving me bonkers. I have one Button that opens the actual spreadsheet itself, and another button the user (AKA: Me) would press to update the spreadsheet with the new information.

Here is the code for the button to open the spreadsheet:

Code:

Private Sub OpenSheet_Click()
Dim oXLApp As Excel.Application      'Declare the object variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet

  Set oXLApp = New Excel.Application  'Create a new instance of Excel
 
  Set oXLBook = oXLApp.Workbooks.Open("c:\Users\EmoKi\Documents\MyXL.xlsx") 'Open an existing workbook
  Set oXLSheet = oXLBook.Worksheets(1)  'Work with the first worksheet
 
  oXLApp.Visible = True              'Show it to the user
 
  Set oXLBook = Nothing              'Disconnect from Excel (let the user take over)
  Set oXLApp = Nothing
  Set oXLSheet = Nothing
End Sub

Here is the code to update the spreadsheet:
Code:

Private Sub UpdateSheet_Click()
Dim oXLApp As Excel.Application        'Declare the object variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
Dim HPNumber As String
  'I have the next few lines commented out because I dont need
  'a new instance or workbook opened.
  'Set oXLApp = New Excel.Application    'Create a new instance of Excel
  'Set oXLBook = oXLApp.Workbooks.Add    'Add a new workbook
  Set oXLSheet = oXLBook.Worksheets(1)  'Work with the first worksheet

    LastRow = oXLSheet.UsedRange.Rows.Offset(1).Select
    LastCol = oXLSheet.UsedRange.Columns.Offset(1).Select




oXLApp.Visible = True                'Show it to the user
  Set oXLSheet = Nothing              'Disconnect from all Excel objects (let the user take over)
  Set oXLBook = Nothing
  Set oXLApp = Nothing

'######################################################################
answer = MsgBox("Save this creation in the spreadsheet?", vbExclamation + vbYesNo, "Confirm")
If answer = vbYes Then

oXLSheet.Cells(LastRow, LastCol).Value = HPNumber

Else
End If
End Sub

What am I doing wrong? It keeps asking for an object, and I thought I told it to use the currently opened worksheet, find the next row and column that are completely empty, and start transferring data. The name of the stats (in order on the spreadsheet) are:
Name, Type, HP, MP, MATK, RATK, MaATK, MDEF, RDEF, MaDEF, Immune, Weakness, Hind/Fly/Climb, Damage Ability

Name and Type are both Text Boxes (user inputs the data themselves)
HP, MP, MATK, RATK, MaATK, MDEF, RDEF, MaDEF are all labels
Immune, Weakness, Hind/Fly/Climb, Damage Ability are all checkboxes (Will come up "YES" in the speadsheet if checked, "NO" if unchecked)

Screenshot posted below as well in case anymore information is needed. It looks super generic but it'll only be used by me so I'm not too worried about it haha.

Name:  PointBuilderScreenshot.jpg
Views: 38
Size:  47.5 KB
Attached Images
 

Viewing all articles
Browse latest Browse all 15685

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>