Modifying Calendar VBA Project - vba

I want to copy from Excel to MS Project some data about a project. These data are gathered in a table in Excel and each column has a title describing the data below.
I need to identify the correct column from which extracting the data, but the method I tried gives me an error which I can't solve.
With the following code I'm looking to identify which columns contain the tasks of the project:
Set taskPos = Worksheets("Sheet1").Range("A1:AA2").Find("Task")
ColTask = taskPos.Column
ColTask should be the column containing the tasks from which I'd like to iterate the elements below.
For i = 2 To 10
exTask = Worksheets("Sheet1").Range("ColTask" & i).Value
Next i
With this method I get a
runtime error 1004 vba application defined or object
and I don't really know how to solve it.
Does anyone have an idea?
Thanks in advance

Related

Microsoft Access 2016 OLE Object & Binary export

I'm trying to write some VBA code to generate a text file containing SQL INSERT statements for all records in a table in an Access database (accdb). The table has an OLE Object field and a Binary field. I can't seem to get them written to the text file properly; I mostly get question marks(?). I've search for solutions and found some possible ideas but none worked.
If any one has suggestions, I will be very appreciative of any help that you can provide.
Miguel
I actually found an solution following some more searching:
Function ByteArrayToHex(B() As Byte) As String
Dim n As Long, I As Long
ByteArrayToHex = Space$(2 * (UBound(B) - LBound(B)) + 2)
n = 1
For I = LBound(B) To UBound(B)
Mid$(ByteArrayToHex, n, 2) = right$("00" & Hex$(B(I)), 2)
n = n + 2
Next
ByteArrayToHex = "0x" & ByteArrayToHex
End Function
Michael
To export OLE objects in a Microsoft Access file, open this file with the Access application and create a corresponding form with all relevant fields. Use the VBA code provided in the link and you should be able to export some of the most common file types in an automated fashion. Good luck.
https://medium.com/#haggenso/export-ole-fields-in-microsoft-access-c67d535c958d

Excel 2013 VBA Runtime Error 5 with listobjects.add

I have a main sub that I am using to set up my worksheets and data for analysis in other subroutines. As part of this I am turning some imported data into a table(data was imported from a CSV file) and placed into "IncidentsData" worksheet. The code for the entire module compiles. However, when I step through the module I get "Run-Time Error '5': Invalid procedure call or argument" on the line where I format the imported data into a table at:
Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes).Name = "IncidentsDataTable"
Here is the overall subroutine:
Public Sub Categorise_Incidents()
Dim incidentsData1 As ListObject
Set Commodity = Worksheets("CommoditySheet").ListObjects("Table1")
Set QEListByGenus = Worksheets("QEListByGenus")
Set Results = Worksheets("Results")
Set IncidentsDataSheet = Worksheets("IncidentsData")
ISDRange = IncidentsDataSheet.UsedRange
Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes).Name = "IncidentsDataTable"
Set incidentsData1 = IncidentsDataSheet.ListObjects("IncidentsDataTable")
initialiseDictionaries
MainSearchLoop QEListByGenus, incidentsData1, dictQENSGenus
End Sub
I have gone to a number of sites to work out how to do this action including:
1. the stack overflow pages on runtime error 5 in excel vba - most of these seem to be specific to pivot tables and didn't tell me what I was doing wrong
2. https://msdn.microsoft.com/en-us/vba/excel-vba/articles/listobjects-object-excel
3. stack overflow questions on creating a table in VBA How to create a table using vba?
4. analysistabs on creating a table in excel vba
https://analysistabs.com/excel-vba/tables-examples/
Plus a bunch of others. Unfortunately, they haven't helped me work out what I am doing wrong. Any help would be greatly appreciated.
Cheers, S26
Edited: to include .Name as that also does not work and throws a runtime error and to fix typos/errors.
First, change xlSrcERange and lYes to xlSrcRange and xlYes.
You're missing the .Name at the end of Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes). You haven't specified which property of the newly created table you want to be "IncidentsDataTable".
Alternately, you can do this:
Set incidentsData1 = Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes)
incidentsData1.Name = "IncidentsDataTable"
If you take that approach, it looks like you don't need to change the Name at all.

MS Access Issue

Hello Stackoverflow community!
I have run into an issue and I'd love some advice.
I'm working with MS Access and I am trying to append two particular fields from one table to another; however this implementation is in a form and it gets a little complicated... So, I'll explain everything the best that I can
BACKGROUND INFORMATION:
First and fore most, I have two tables; one of which is a linked excel spread sheet from another directory (who is not willing to change any formatting what so ever, so I CANNOT make ANY changes to this file and it is being updated on a daily basis). This excel spreadsheet is very large and contains somewhere around 50 columns
The other table is not anywhere near as large but has around 20 columns and is meant to extract two columns from the excel spreadsheet (the first column and the third column). I'm trying to make a form for this database to be as user-friendly as possible and not many people in my office are familiar with the technicalities of Access queries and programming in VBA.
THE SITUATION:
On my form, the user will enter data into TextBoxA, from there they will click a button; this button will trigger a search through the linked excel spreadsheet for the data that was typed into TextBoxA. It will then copy the data from Field1 (which was the typed data) and Field3 and append these selected fields into the first two fields of the table in my Access Database. All of this is being done through a segment of VBA code
Private Sub CmdCloseForm_Click()
If IsNull(Me.TextBoxA) Or Me.TextBoxA = "" Then
MsgBox ("Field is empty, please try again!")
Else
Dim VendorNum As String
SearchingValue = Me.TextBoxA
Dim SQL As String
SQL = "INSERT INTO tbleRecord (Field1,Field2)" & _
"SELECT * " & _
"FROM tbleLinkedExcel " & _
"WHERE Field1 = '" & SearchingValue & "';"
DoCmd.RunSQL SQL
End If
End Sub
So the biggest issue here is that in Field1, and every time I try to run the code,
I receive an error; which I am assuming it is because of the space (unfortunately I cannot give the ACTUAL variable names out as it is confidential)
ERROR MESSAGE
The INSERT INTO statement contains the following unknown field name: 'FIELD 1'. Make sure you have typed the name correctly, and try the operation again.
The thing is, is that this 'FIELD 1' variable/name is not in my code, but in the linked excel spreadsheet (again, I am not able to change ANYTHING on this spreadsheet).
Thanks guys!

Deleting and creating an userform with the same name dynamically

Hi I'm actually coding to delete all the userforms of a project and recreate them by using a XML file.
The problem is that when I delete a userform and I want to recreate it with the same name, I get the following error "Run-time error '75' - Path/File error".
I use this to delete userforms :
Application.VBE.VBProjects(iMyName).VBComponents.Remove VBComponent:=.Item(x)
Where iMyName is the project name and x the variable in my loop.
And just after I use:
Set ihm_f = .Add(vbext_ct_MSForm)
ihm_f.Properties("Name") = "CA"
Where ihm_f is my new userform and CA the name of the previous Userform I deleted for example.
Do someone know how to do ?
Try Saving the Workbook between Removing and re-Creating.
Works for me, but I would be interested to knows a better way.

Delete top row of excel file using SSIS

I have an excel file that has a header row which is a row that I want to delete. The header row in thsi file are the cells of A1 to W1 merged into one. This causes a problem when I try to read the file because I am expecting column names. Proper column names exist in the second row of the file, which is why I want to delete the first.
To accomplish this I thought I'd be able to use the 'Excel Source' item in SSIS since it supports a SQL option to write a query. What I want to do is something like this:
SELECT * from ExcelFile WHERE Row > 1
My file only has data in columns A thru W.
I don't know what syntax I can use in the query to do this. The query builder that is in the Excel Source item will allow me to do many things with columns but I don't see an option for doing anything with rows. Searching online and using the help didn't get me anywhere.
None of these solutions will work because the Excel driver will be confused by the merged first line. You won't be able to use any driver features such as skip first row to do this. You need to run some script to open the Excel file and delete the row manually.
There is some basic sample script at this site:
http://www.sqlservercentral.com/Forums/Topic1327014-1292-1.aspx
The code below is adapted from the code written by snsingh at that site.
You would obviously want to use connnection manager properties, not hard coded paths
Excel needs to be installed on the SSIS Server for it to work - this is the only way to use Excel automation.
Dim filename As String
Dim appExcel As Object
Dim newBook As Object
Dim oSheet1 As Object
appExcel = CreateObject("Excel.Application")
filename = "C:\test.xls"
appExcel.DisplayAlerts = False
newBook = appExcel.Workbooks.Open(filename)
oSheet1 = newBook.worksheets("Sheet1")
oSheet1.Range("A1").Entirerow.Delete()
newBook.SaveAs(filename, FileFormat:=56)
appExcel.Workbooks.Close()
appExcel.Quit()
You don't need to use a syntax.
Go to control flow..
Pull in a data flow task.
Add a excel file source...add a conection manager
With excel sheet.
Open your connection manager and then check the box which says.
Column names In first row. That's it and add ur destination.