Hi i am using Access form to create a macro button for excel does anyone knows how to do it cause i got problems doing it.
Printable View
Hi i am using Access form to create a macro button for excel does anyone knows how to do it cause i got problems doing it.
What specific problems are you running into?
Dim xlApp As Excel.Application
Dim xlWB As Excel.Workbook
Dim i As Integer
Dim Number As Integer
rst.Open "select * from ans_table", CurrentProject.AccessConnection, adOpenDynamic, adLockOptimistic
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
sFullPath = CurrentProject.Path & "\ExcelFile.xls"
Set xlWB = xlApp.Workbooks.Open(sFullPath) ' create a new workbook
With xlWB.Worksheets(1)
' For i = 1 To 100
.Cells(4, 2).Formula = "Male"
.Cells(5, 2).Formula = "Female"
' Next i
' If Dir("C:\Documents and Settings\Gabriel\Desktop\Excel\MyNewExcelWB.xls") <> "" Then
' Kill "C:\Documents and Settings\Gabriel\Desktop\Excel\MyNewExcelWB.xls"
' End If
' .SaveAs ("C:\Documents and Settings\Gabriel\Desktop\Excel\MyNewExcelWB.xls")
End With
ActiveSheet.CheckBoxes.Add(Cells(4, 3).Left, Cells(4, 3).Top, 80, 10).Select
With Selection
.Text = "1"
.Name = "CheckBox1"
End With
ActiveSheet.CheckBoxes.Add(Cells(5, 3).Left, Cells(5, 3).Top, 80, 10).Select
With Selection
.Text = "2"
.Name = "checkbox3"
End With
' i = 7
' rst.MoveFirst
' Do While Not rst.EOF
' ActiveSheet.CheckBoxes.Add(Cells(i, 2).Left, Cells(i, 2).Top, 80, 10).Select
' With Selection
' .Text = rst!answer
' .Name = "box1"
' End With
' rst.MoveNext
' i = i + 1
' Loop
i = 7
Number = 1
rst.MoveFirst
Do While Not rst.EOF
With xlWB.Worksheets(1)
' For i = 1 To 100
.Cells(i, 2).Formula = rst!Answer
ActiveSheet.CheckBoxes.Add(Cells(i, 11).Left, Cells(i, 11).Top, 80, 10).Select
With Selection
.Text = Number
' .Name = "box1"
End With
End With
i = i + 1
Number = Number + 1
rst.MoveNext
Loop
' ActiveSheet.OptionButtons.Add(Cells(8, 3).Left, Cells(8, 3).Top, 80, 10).Select
' With Selection
' .Text = "2"
' .Name = "box1"
' End With
' ActiveSheet.TextBoxes.Add(55.5, 70.75, 77.25, 18.75).Select
' xlWB.Close False ' close the workbook without saving
' xlApp.Quit ' close the Excel application
Set xlWB = Nothing
Set xlApp = Nothing
End Sub
I dunno how to create a macro at excel so that when i click the checkbox1 a msgbox will appear
Please use the [ vbcode][/ vbcode] tags around your code to make it easier on the eyes..
Rather than trying to create the macro in Excel, do you want to explain exactly what you are trying to do with the spreadsheet?