Long story short the person that wrote that no longer works with us, I am very inexpeirenced in writing VBA's. He had a spreadsheet that I inserted a png.image into then used text boxes laid over with road #'s and field names. Then it has a export field command box that would export it to where it was supposed to go. I recently upgraded to Excel 2013 and this program no longer works, when I hit export field i receive a System Error &H80004008 (-2147467259) unspecified error. I will post the code he wrote. Any pointers will be extremely helpful.
Sub pasteField()
'Dim fieldnum As Integer
'fieldnum = ActiveSheet.Range("Q3").Value
'fieldnum = fieldnum + 1
'ActiveSheet.Range("Q3").Value = fieldnum
ActiveSheet.Range("Q3").ClearContents
Range("B3").Select
ActiveSheet.Paste
End Sub
Sub resizeField()
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 253.5
Selection.ShapeRange.Width = 253.5
Selection.ShapeRange.Rotation = 0#
Selection.ShapeRange.ZOrder msoSendToBack
End Sub
'Private
Sub exportField()
Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim field1 As String
Dim field2 As String
'Make sure a grower is selected before exporting
If ActiveSheet.Range("Q3").Value = "" Then
MsgBox ("Please enter a valid field number before attempting to export.")
Exit Sub
Else
Application.ScreenUpdating = False
'Create file name for Grower files
If Range("S3").Value = "" Then
field1 = "F:\my DOCUMENTS\Growers\Growers\" & ActiveSheet.Range("R3").Value & "\Field Maps\" & ActiveSheet.Range("R3").Value & " " & ActiveSheet.Range("Q3").Value & ".png"
Else
field1 = "F:\my DOCUMENTS\Growers\Growers\" & ActiveSheet.Range("R3").Value & "\Field Maps\" & ActiveSheet.Range("R3").Value & " " & ActiveSheet.Range("Q3").Value & " - " & ActiveSheet.Range("S3").Value & ".png"
End If
'Create file name for Overall maps
field2 = "F:\my DOCUMENTS\Fields\Field Maps\" & ActiveSheet.Range("Q3").Value & ".png"
'Check to see if file already exists in Grower files, if so deletes it so new file can be saved
If FileFolderExists(field1) Then
Kill (field1)
Else
End If
'Check to see if file already exists in Overall maps, if so deletes it so new file can be saved
If FileFolderExists(field2) Then
Kill (field2)
Else
End If
'Creates a chart within "Area Map" Sheet and pastes the image in it
Set oRange = Range("B3:M17")
Set oCht = ActiveSheet.ChartObjects.Add(Left:=0, _
Top:=oRange.Top + oRange.Height + 10, _
Width:=oRange.Width, Height:=oRange.Height).Chart
With ActiveSheet.Shapes(oCht.Parent.Name)
.fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
oRange.CopyPicture xlScreen, xlPicture
oCht.Paste
'Exports to Grower files
oCht.export Filename:=field1, Filtername:="png"
'Exports to Overall maps
oCht.export Filename:=field2, Filtername:="png"
'Deletes Chart from sheet
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Application.ScreenUpdating = True
'Clears out grower name to prepare for next export
ActiveSheet.Range("Q3").ClearContents
End If
End Sub
Sub pasteField()
'Dim fieldnum As Integer
'fieldnum = ActiveSheet.Range("Q3").Value
'fieldnum = fieldnum + 1
'ActiveSheet.Range("Q3").Value = fieldnum
ActiveSheet.Range("Q3").ClearContents
Range("B3").Select
ActiveSheet.Paste
End Sub
Sub resizeField()
Selection.ShapeRange.LockAspectRatio = msoTrue
Selection.ShapeRange.Height = 253.5
Selection.ShapeRange.Width = 253.5
Selection.ShapeRange.Rotation = 0#
Selection.ShapeRange.ZOrder msoSendToBack
End Sub
'Private
Sub exportField()
Dim oRange As Range
Dim oCht As Chart
Dim oImg As Picture
Dim field1 As String
Dim field2 As String
'Make sure a grower is selected before exporting
If ActiveSheet.Range("Q3").Value = "" Then
MsgBox ("Please enter a valid field number before attempting to export.")
Exit Sub
Else
Application.ScreenUpdating = False
'Create file name for Grower files
If Range("S3").Value = "" Then
field1 = "F:\my DOCUMENTS\Growers\Growers\" & ActiveSheet.Range("R3").Value & "\Field Maps\" & ActiveSheet.Range("R3").Value & " " & ActiveSheet.Range("Q3").Value & ".png"
Else
field1 = "F:\my DOCUMENTS\Growers\Growers\" & ActiveSheet.Range("R3").Value & "\Field Maps\" & ActiveSheet.Range("R3").Value & " " & ActiveSheet.Range("Q3").Value & " - " & ActiveSheet.Range("S3").Value & ".png"
End If
'Create file name for Overall maps
field2 = "F:\my DOCUMENTS\Fields\Field Maps\" & ActiveSheet.Range("Q3").Value & ".png"
'Check to see if file already exists in Grower files, if so deletes it so new file can be saved
If FileFolderExists(field1) Then
Kill (field1)
Else
End If
'Check to see if file already exists in Overall maps, if so deletes it so new file can be saved
If FileFolderExists(field2) Then
Kill (field2)
Else
End If
'Creates a chart within "Area Map" Sheet and pastes the image in it
Set oRange = Range("B3:M17")
Set oCht = ActiveSheet.ChartObjects.Add(Left:=0, _
Top:=oRange.Top + oRange.Height + 10, _
Width:=oRange.Width, Height:=oRange.Height).Chart
With ActiveSheet.Shapes(oCht.Parent.Name)
.fill.Visible = msoFalse
.Line.Visible = msoFalse
End With
oRange.CopyPicture xlScreen, xlPicture
oCht.Paste
'Exports to Grower files
oCht.export Filename:=field1, Filtername:="png"
'Exports to Overall maps
oCht.export Filename:=field2, Filtername:="png"
'Deletes Chart from sheet
Dim wsItem As Worksheet
Dim chtObj As ChartObject
For Each wsItem In ThisWorkbook.Worksheets
For Each chtObj In wsItem.ChartObjects
chtObj.Delete
Next
Next
Application.ScreenUpdating = True
'Clears out grower name to prepare for next export
ActiveSheet.Range("Q3").ClearContents
End If
End Sub